0

I have a sample code:

$('.tab').click(function(){
     $('head').append('<link href="\"style.css\"" rel="\"stylesheet\"" type="\"text/css\"">');
     $('head').append('<script src="\"click.js\"" type="\"text/javascript\""></script>');
});

This code only add file css on head, can't add click.js on head, how to fix

Hai Truong IT
  • 4,126
  • 13
  • 55
  • 102
  • you shouldn't have to escape the double quotes if it is in single quotes. try removing all those escape characters. – mrtsherman Feb 07 '12 at 04:36
  • possible duplicate of [jQuery: Can't append – Jeremy Feb 07 '12 at 04:37
  • gonna guess that that's in an HTML file and that `` is ending the script element. use `<\/script>` instead. Alternatively, post more code so that we can see where it's getting called. – zzzzBov Feb 07 '12 at 04:42

2 Answers2

0

If you just want to load and execute the script, you can do this:

$.getScript("click.js");

I don't see why you need it in the head.

grc
  • 22,885
  • 5
  • 42
  • 63
0

From the post

var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
$("#someElement").append(script);

Please search question on SO, and if you don't find any answer, then post new question.

Hope this solution works for you.

Community
  • 1
  • 1
Amar Palsapure
  • 9,590
  • 1
  • 27
  • 46