How do I select a span containing a specific text value, using jquery?

后端 未结 4 1172
悲哀的现实
悲哀的现实 2020-12-28 11:40

How do I find the span containing the text \"FIND ME\"

FIND ME dont find me
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-28 12:05

    http://api.jquery.com/contains-selector/

    $("span:contains('FIND ME')")
    

    ETA:

    The contains selector is nice, but filtering a list of spans if probably quicker: http://jsperf.com/jquery-contains-vs-filter

    $("span").filter(function() { return ($(this).text().indexOf('FIND ME') > -1) }); -- anywhere match
    $("span").filter(function() { return ($(this).text() === 'FIND ME') }); -- exact match
    

提交回复
热议问题