从h3元素获取文本而不从h3的子元素获取文本 [英] Get Text from h3 element without getting text from child elements of h3
本文介绍了从h3元素获取文本而不从h3的子元素获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这就是我想要的:
<h3 class="ExpressCheckoutTitle">
<a onclick="" href="#" class="ChangeLink">Modify »</a>
Step 4: Order Confirmation
</h3>
我只想获取文本第4步:订单确认"
I want to get just the text "Step 4: Order Confirmation"
$('h3.ExpressCheckoutTitle').text()
给出了<a>
元素中的文本,例如:修改>>步骤4:订单确认"
$('h3.ExpressCheckoutTitle').text()
gives me the text from the <a>
element as well like this: "Modify >> Step 4: Order Confirmation"
如何在jquery中做到这一点?
How do I do this in jquery?
推荐答案
您可以使用contents()
直接访问textNode.试试这个:
You can use contents()
to access the textNodes directly. Try this:
var text = $("h3").contents().filter(function() {
return this.nodeType == 3;
});
这篇关于从h3元素获取文本而不从h3的子元素获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文