Reputation:
Assume the follow code
<div class="hello">
<h2>I'm a header</h2>
</div>
<script>
foo = $('.hello');
</script>
How do I select the h2 tag from foo and replace it's contents?
I'm basically looking for the equivalent of $('.hello > h2).html('New header') but on the variable.
Upvotes: 0
Views: 54
Reputation: 1104
To get a child of a jQuery object you can use children():
var foo = $('.hello');
foo.children('h2').html('New header');
Upvotes: 0
Reputation: 36957
Are you looking for:
foo = $('.hello');
foo.find('> h2').html('New Header');
Upvotes: 2