+ 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 .
2 Antworten
+ 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'
0
Thanks