Reputation: 980
What I am trying to do is change the contents of a div within a div. I can't seem to access it.
dialog is the parent while dialogChange is the child.
When I do:
$("#dialog").text("New Text");
It'll replace everything within the parent, dialog.
But when I do:
$("#dialogChange").text("New Text");
Nothing changes.
So how can I access the child within a parent?
Upvotes: 0
Views: 113
Reputation: 65238
How about something like this:
$('parent').find('child').text('New Text');
Upvotes: 1
Reputation: 24070
Instead of using the text method, which replaces the entire contents of the div, you should try some of these methods:
.before()
.after()
.append()
For example, you could use $("#dialogChange").before("New Text")
to insert something before that div.
Play around for the exact effect you want, and use the API as a guide:
Upvotes: 1
Reputation: 6986
If you do $("#dialog").text("New Text");
, this will effectively remove dialogChange, so $("#dialogChange").text("New Text");
won't work.
Upvotes: 5
Reputation: 5157
Your jQuery looks good. Possibly the problem is in your HTML.
Or by any chance have your replaced the contents of the parent (and therefore deleted the child) before you call the code affecting the child?
Upvotes: 0