开发者

a tag toUpperCase comparison

Given:

<div>
  <span><a href="#">abc</a></span>
  <span><a href="#">def</a></span>
</div>

Is there a way to do 开发者_Python百科a string comparison with toUpperCase() between a given string value and the link text (as shown above in the span collection) and if it doesn't match hide the span? Anyway to incorporate "contains" in the mix?

Thanks,

rod.


You could do the following. But keep in mind this will run for all a tags within a span. You should modify it will a id on your div or some kind of class attribute.

$('span a').each(function() {
  var anchor = $(this);
  if (anchor.text().toUpperCase() == 'ABC') {
    anchor.hide();
  }
});

See it in action: http://jsfiddle.net/KCCVm/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜