最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Select element based on text - Stack Overflow

programmeradmin5浏览0评论

I want to select an element based on their innertext in JQuery. Below is my Html

<html>
    <body> 
        <a href="fddf">4</a> 
        <a href="fddf">4</a> 
        <a href="fddf">4</a> 
    </body> 
</html>

I want to select all the <a> tags which has text of "4". Any idea how do I do it?

I want to select an element based on their innertext in JQuery. Below is my Html

<html>
    <body> 
        <a href="fddf">4</a> 
        <a href="fddf">4</a> 
        <a href="fddf">4</a> 
    </body> 
</html>

I want to select all the <a> tags which has text of "4". Any idea how do I do it?

Share Improve this question edited Apr 4, 2013 at 20:33 abatishchev 100k88 gold badges301 silver badges442 bronze badges asked Jul 2, 2010 at 15:54 s gandhis gandhi 1011 silver badge3 bronze badges 2
  • You can add HTML or source code to your question by indenting it with four spaces. (or by clicking the Format Code (1010) button in the toolbar) – SLaks Commented Jul 2, 2010 at 15:57
  • possible duplicate of stackoverflow./questions/1430290/jquery-select-based-on-text – goodeye Commented Apr 19, 2012 at 5:58
Add a ment  | 

2 Answers 2

Reset to default 16

You're looking for the :contains selector, like this:

$('a:contains("4")')

I think the correct way is $("a[outerText='4']"). Contains returns 4,44,444 etc. .

发布评论

评论列表(0)

  1. 暂无评论