Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding HTML code with Single Quotes inside jQuery

I am trying to add this HTML/JavaScript code into a jQuery variable. I've managed to insert double quotes by writing is with a backshlash \", however the same tactic didn't work for the single quotes:

ajaxData += '<div class=\"menu-item-' + $(this).attr('div') + 'onclick=\"alert('Jquery Function');\"></div>';

Specifically, this part onclick=\"alert('Jquery Function');

Anyone know how I can go around this?

like image 299
pufAmuf Avatar asked Dec 11 '22 19:12

pufAmuf


2 Answers

See this, its beautiful:

ajaxData += '<div class="menu-item-' + $(this).attr('div') + ' onclick="alert(\'Jquery Function\');"></div>';
like image 192
Lenin Avatar answered Feb 24 '23 19:02

Lenin


Dirty escape pheeww...Try this

ajaxData += '<div class="menu-item-' + $(this).attr('div') + 'onclick="alert(\'Jquery Function\');"></div>';
like image 45
Mr. Alien Avatar answered Feb 24 '23 20:02

Mr. Alien