Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding script as string into textarea value

The question is pretty self explanatory. What I want to do is changing the value of a textarea with jQuery. What I do is:

$( '#embedcode' ).val( "<script id='embed_1' src='/javascripts/test.js' type='text/javascript'></script>" );

What is the right way to do that. I keep getting an error :

Uncaught SyntaxError: Unexpected identifier

How to make the that I want to add as a string not a script.

like image 684
ishwr Avatar asked Dec 15 '22 06:12

ishwr


1 Answers

Here you go:

Make your String like this :

$('#embedcode').val("<script id='embed_1' src='\/javascripts\/test.js' type='text\/javascript'><\/script>");

Check out this JsFiddle i made for you:

http://jsfiddle.net/KB9Qn/14/

like image 144
Hassan Sardar Avatar answered Jan 01 '23 10:01

Hassan Sardar