Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I append to a <h1> tag inside a span with jQuery?

jsFiddle

I'm trying to append some text to a heading that is in a span. But I don't know how to append to the actual heading, and not just the span.

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 gets appended after the heading tag, and therefore doesn't have the heading style applied to it. How can I append to the heading?

like image 724
ben Avatar asked Dec 28 '22 00:12

ben


1 Answers

http://jsfiddle.net/bTubp/2/

$('.note h1:first-child').append("more text");

for inserting inside the first h1 of every .note class

and

$('.note:first-child h1').append("more text");

for inserting inside text for h1 of first .note class

For first h1 of first .note

$('.note:first-child h1:first-child').append("more text");
like image 172
Santosh Linkha Avatar answered Jan 19 '23 04:01

Santosh Linkha