开发者

jQuery - How to select all elements with a set font-family applied to them?

I need a way for jQue开发者_开发技巧ry to return all elements that have the css

font-family:AvantGardeITCbyBT-Bold, sans-serif;

applied to them.

I'm thinking the only way of doing this is looping through all elements and checking if this css is applied to it. Seems a slow way of doing it?

Is there a way of doing this via a jQuery Selector?


well, you can extend the jQuery selectors with

$(document).ready(function(){
   $.extend($.expr[':'], {
     AvantGardel: function(elem){
        var $e = $(elem);
        return( typeof $e.css('font-family') !== 'undefined' && $e.css('font-family') === 'AvantGardeITCbyBT-Bold' );
     },
     SansSerif: function(elem){
       var $e = $(elem);
        return( typeof $e.css('font-family') !== 'undefined' && $e.css('font-family') === 'sans-serif' );
     }
 });    
});

and then call

$(':AvantGardel').hide();

or

$(':SansSerif').hide();

for instance.

working example: http://jsbin.com/idova3/edit

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜