如何附加到< h1> jQuery跨度内标记? [英] How can I append to a <h1> tag inside a span with jQuery?

查看:77
本文介绍了如何附加到< h1> 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.

样式:

h1 {font-size:250%;color:red;}

HTML:

<span class="note">
    <h1>
        some text
    </h1>
</span>

我运行这个:

$('.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?

推荐答案

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

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

用于插入每个.note类的第一个h1

for inserting inside the first h1 of every .note class

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

用于为第一个.note类的h1插入内部文本

for inserting inside text for h1 of first .note class

对于第一个.note的第一个h1

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

这篇关于如何附加到&lt; h1&gt; jQuery跨度内标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆