Caio Gomes
Caio Gomes

Reputation: 123

Script not printing using jquery

I need to print a script using jquery but the script code is not printed and the rest is, does anyone know how to solve this? Following code below:

codigo = '<div id="teste"><input type="submit" id="botao" value="Send" /><script>$("#botao").click(function() { alert("test"); });</script></div>';
$('#iframe5').parent().after(codigo);

Upvotes: 0

Views: 66

Answers (2)

Philipp Sander
Philipp Sander

Reputation: 10249

codigo = '<div id="teste"><input type="submit" id="botao" value="Send" /><script>$("#botao").click(function() { alert("test"); });</script></div>';
$('#iframe5').parent().after(codigo);

there was a problem with your quotes

Upvotes: 0

Arunkumar Srisailapathi
Arunkumar Srisailapathi

Reputation: 1169

Problem is with quotes. Try changing the quotes properly and everything should work just fine.

codigo = '$(\'#botao\').click(function() { alert(\'test\'); });'; $('#iframe5').parent().after(codigo);

I guess this should work.

Try adding \' for escaping quotes.

Hope this helps.

Upvotes: 2

Related Questions