开发者

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

开发者 https://www.devze.com 2023-01-03 07:16 出处:网络
I need a way for jQue开发者_开发技巧ry to return all elements that have the css font-family:AvantGardeITCbyBT-Bold, sans-serif;

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

精彩评论

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