using jquery.attr ()? It seemed...">

Changing the src <script> attribute

Is it possible to change the "src" attribute of an existing element <script>using jquery.attr ()? It seemed like a simple way to get JSONP to work, but I can't do this work for me.

+5
source share
3 answers

It turns out that a script srccan only be set once ! Unable to change the attribute of an srcexisting element <script>in the DOM. However, a dynamically created element <script>can have its own source set (but exactly once !)

+15
source

If you are trying to load a script, you can use getScript instead.

http://api.jquery.com/jQuery.getScript/

, src , script , data-id, HTML5, src. src, attr. script .

+3

, , , , jQuery JSON-P. . $.getJSON $.ajax .

+3

All Articles