Shahin
Shahin

Reputation: 12861

jquery does not work on loaded html

I'm appending HTML tags from html file to body using jQuery.After I loaded html tags I am loading JS file that doing something on html tags.jQuery does not work on loaded html but when I putting html tags statically on page jQuery working on it right.
I use this code to append html tags to body
What's the problem ?
Its my target html tags

  function DisplayLoginPanel() {
        $('Body').load('Resources/HTMLContents/Login.htm');
        LoadNewScript("Resources/OtherTools/js/slide.js");
    }
    function LoadNewScript(ScriptPath) {
        $.getScript(ScriptPath, function () {
            alert("Script loaded and executed.");

        });
    }

Upvotes: 4

Views: 436

Answers (1)

Niklas
Niklas

Reputation: 30012

If I understood your question correctly, then you need to add the LoadNewScript() function inside a complete event for the .load() function. Like this:

function DisplayLoginPanel() {
$('Body').load('Resources/HTMLContents/Login.htm', function() {
  LoadNewScript("Resources/OtherTools/js/slide.js");
});
}

The reason for this is that when you initiate the load() your javascript keeps going forward. It doesn't wait for the login.html to be loaded and as such, the LoadNewScript is called before the html has been added.

Have a look at the documentation for more details.

Upvotes: 4

Related Questions