如何在DIV之后从段落中使用jQuery获取文本?

时间:2011-08-28 17:17:46

标签: jquery

我不知道该怎么办。使用jQuery我想得到Div之后带有“ban_hdr”类的第一段的文本。

<div class="ban_hdr">
</div>
<p>Which of the following are correct? abc abc</p>

如果我能得到第一句的内容总是以“?”

结尾,那就更好了

3 个答案:

答案 0 :(得分:4)

var text = $('.ban_hdr').next('p').text();

Demo

答案 1 :(得分:1)

尝试使用此$('div+p').text();来指定类 alert($('div.ban_hdr + p').text());

答案 2 :(得分:0)

要从div中的段落标记中读取文本,请使用此

$("#ban_hdr").children("p").text();

&安培;将文本写入div内的段落标记使用此

$("#ban_hdr").children("p").text("new text in p tag. Hope this helps :P ");