How can I add the <h1> tag inside a range using jQuery?
I am trying to add some text to a title that is in between. But I do not know how to add to the actual header, not just the range.
Style:
h1 {font-size:250%;color:red;} HTML:
<span class="note"> <h1> some text </h1> </span> I run this:
$('.note:first-child').append("more text"); But the text is added after the title tag and therefore does not have the style of the title applied to it. How can I add a title?
You need a place for your selector to do what you mean:
$('.note :first-child').append("more text"); or
$('.note > :first-child').append("more text"); See DEMO:
When you say: .note:first-child it means something with a class note, which is also the first child of its parent. When you say: .note :first-child it means something that is the first child of its parent and inside (perhaps deeply) something with a class entry. When you say: .note>:first-child it means: something that is the first child of his parent and his parent class has a class note, and that is probably what you had in mind.
I see that there are already many answers before I finish writing, but I will publish it anyway, because I hope it will explain why your selector is not working.