Attach the <script> tag to the head
Hi fellas!
I have a problem with adding some script files to my page. I update all the content on the page via ajax, so if on a new page I have some new js/css - files I haven't on previous, I need to attach 'em. In success method:
- // Attach the css files
- if ( css.length > 0 ) {
- for ( var i in css ) {
- if ( $('link[href="' + css[i] + '"]').length == 0 ) {
- $('<link />', {
- href : css[i],
- media : 'all',
- rel : 'stylesheet'
- }).appendTo('head');
- }
- }
- }
- // Attach the js files
- if ( scripts.length > 0 ) {
- for ( var i in scripts ) {
- if ( $('script[src="' + scripts[i] + '"]').length == 0 ) {
- $('<script/>', {
- src : scripts[i],
- type : 'text/javascript'
- }).appendTo('head');
- }
- }
- }
The css files has added as excected, but the script files has not. Instead of that I had the GET requests to each of the files.