开发者

Hide Links not containing my Keyword (Case Sensitive)

I'm using this shopping cart script that sends Links to my own website. Meaning I h开发者_运维问答ave no control over the HTML.

The links look like this:

<a href="something.com">Yamaha 800cc motorbike</a>
<a href="something.com">800cc Kawasaki</a>
<a href="something.com">Motorbike 1000cc Honda</a>

And there are variations in which the anchor text Casing is different as well.

ie:

<a href="something.com">YAMAHA 800cc motorbike</a>
<a href="something.com">yamaha 1000cc motorbike</a>

My Goal:

HIDE all Links that Do Not have Yamaha, yamaha or YAMAHA in the anchor text. (all text casings)

To end up with Yamaha motorbikes only.

Anyone know how to do this?

Thanks and best regards,

Chakhun


$('a').filter(function() {
   return ! $(this).text().match(/Yamaha/i);  
}).hide();

jsFiddle.


Could look like:

$('a').each(function(_, elem) {
    var $elem = $(elem);
    if( !/yamaha/i.test( $elem.text() ) )
        $elem.hide();
});

Demo: http://jsfiddle.net/r4Yeh/2


Make use of :contains() Selector

<script>
$("a:contains('YAMAHA')").css("display", "inline");
    </script>

for more details about this : Is there a case insensitive jQuery :contains selector?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜