1

I'm using jquery.load() to dynamically load sections of a page. But I'd like the included sections to both include HTML and be able to execute script. But a simple

<script>
    alert("hello");
</script>

doesn't run when I AJAX it in. Is there another way to dynamically load content such that the scripts will run, or a way to manually run scripts in the included content? In this case I'm relying on the way jquery.load only includes a specific selector from the loaded page.

FWIW I'm using Jquery 1.4.2.

Leopd
  • 41,333
  • 31
  • 129
  • 167
  • 2
    http://stackoverflow.com/questions/235967/calling-a-jquery-function-inside-html-return-from-an-ajax-call – m_vitaly Oct 27 '10 at 20:25
  • possible duplicate of [Javascript won't execute after load](http://stackoverflow.com/questions/2176279/javascript-wont-execute-after-load) – Jürgen Thelen Aug 20 '12 at 09:14

1 Answers1

1

Try changing the script in the loaded page to:

<script>
    $(function(){
        alert("hello");
    });
</script>

This should make it run when it's loaded.

gen_Eric
  • 223,194
  • 41
  • 299
  • 337