How to put single quote with in single quote in jquery string ?

  By zahid   Posted on July-12-2018   515

JQuery

var buttonString = "<button onclick='window.webkit.messageHandlers.callbackHomePageHandler.postMessage('Redirecting to Home');' class='agree' style='color:#EE8B13;border:none;background:white;padding:0px 3px'> <b>here</b>&nbsp; </button>";

 

In above example, onclick event has single quote with in single quote. This syntax give error when its render in browser. 

Solution:  replace inner single quote with &#39;

var buttonString = "<button onclick='window.webkit.messageHandlers.callbackHomePageHandler.postMessage(&#39;Redirecting to Home&#39;);' class='agree' style='color:#EE8B13;border:none;background:white;padding:0px 3px'> <b>here</b>&nbsp; </button>"

By  zahid.0028    12-Jul-2018 Views  515



You may also read following recent Post

Submit Post - Article - Ask a Question - Ask an Interview Question - Submit Useful Links