2

Does anyone know if it possible to change HTML with jQuery that appears below the script?

I'm using: $("div.className").html("My changed HTML here"); to change some text on a page. However it seems to only work if that HTML appears somewhere above the script placement. Is it possible to have it work on HTML that appears below the script placement? Or does the script need to be the last thing to load on the page?

Thanks for any help.

1

2 Answers 2

2

You need to put your jQuery-enabled code into a $(document).ready() block:

$(document).ready(function() {
    $("div.className").html("My changed HTML here");
});

Your code wasn't working because you were looking for an element that hasn't been created yet.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah Ha! Thanks everyone for the quick response.
0

put in ready function.Then it will work.Like

 $(document).ready(function() {
    $("div.className").html("My changed HTML here");
});

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.