0

I'm having trouble getting my scripts to run for content that has been loaded onto the page via .load().

In particular, how do you make a script that should run on .ready work?

Sample script:

$(document).ready(function() {
    $('.content').fadeIn();
});

-- It runs fine on standard pages, but won't work for .load() sections.

1
  • where is the .load() happening ? Commented Mar 13, 2014 at 16:02

3 Answers 3

1

You have no slow variable defined. It should be a string, so:

$(document).ready(function() {
    $('.content').fadeIn('slow');
});
Sign up to request clarification or add additional context in comments.

Comments

1

async functions come with a callback, use that to perform operations on the content once the load is complete:

$("yourElementSelector").load("url", function() {
    //load is completed, do work here
});

2 Comments

I'm hoping to find a solution other than callbacks. I'm using a handful of .load'ed sections in place of simple links - having to put all relevant scripts into a callback on the original .load would be a mess
Ehh...when using async operations, callbacks or promises are why you need.
0

Your event will only run when the page is first loaded and ready, any other event such as .load() will need additional event handlers attached.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.