简体   繁体   English

jQuery的选择带有标签的文本

[英]jquery select text with tag

Is it possible to select text inside < P> with other tag like < b>,< i> for eg 是否可以在<P>内选择带有其他标签(例如<b>,<i>)的文本,例如

<td rowspan="2" width="28%" valign="top" > 
<p>Hello <b> John</b>< p>
</td>

here in above example, is it possible to fetch "Hello < b> John" with jquery selector 在上面的示例中,是否可以使用jquery选择器获取“ Hello <b> John”

Use jQuery .html() to get html content. 使用jQuery .html()获取html内容。 Try this: 尝试这个:

$(function() {
  alert($("p").html()); 
});

DEMO 演示

$('p').html();

将是您所需要的。

$('p').html();

会得到你

Hello <b> John</b>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM