+ 1

Want to alert script src web address

If i try that $('script').attr('src'); It should use the right value. But it's showing undefined .

9th Apr 2017, 11:45 PM
Shyam Sundar
Shyam Sundar - avatar
2 odpowiedzi
+ 6
// I'm not user of JQuery, but: $('script'); // should select all <script>s element in actual html document ( dom ), so you probably need to // 1> have at least one <script> tag in the actual dom // 2> select one in the returned list // more accurate way is to set an unique id to the targeted <script>: // for a <script id="myscript">, use: $('#myscript'); // Anyway, the targeted script need to have his 'src' attribute set to read another value than 'undefined' ^^ // for a <script id="myscript" src="url"></script>, use: alert($('#myscript').attr('src')); // output 'url' // but for a <script id="myscript">/* inlined code */</script> alert($('#myscript').attr('src')); // output 'undefined'
10th Apr 2017, 3:31 AM
visph
visph - avatar
0
Thanks
12th Apr 2017, 12:16 AM
Shyam Sundar
Shyam Sundar - avatar