0

I am trying to set text for a div which is located in external html file, but when I give the ID of that div, it is not recognized, what should I do? I load the external HTML file like this:

$('#header').load("resources/html/header.html");

then I try to set "headerTitle" which is inside header.html

$('#headerTitle').text($('#buidlingComboBox :selected').text());  

If I give an ID which is inside main HTML file, it works fine.

1 Answer 1

2

You probably have to wait until the content is available, and load() has a handy callback for that :

$('#header').load("resources/html/header.html", function() {
    $('#headerTitle').text( $('#buidlingComboBox').val() );  
});
Sign up to request clarification or add additional context in comments.

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.