jQuery filter selector, is this right?

Posted by fire on Stack Overflow See other posts from Stack Overflow or by fire
Published on 2010-06-03T09:56:27Z Indexed on 2010/06/03 10:44 UTC
Read the original article Hit count: 132

Filed under:
|

It seems to work ok but I don't know if this can be impoved on or not.

I want to select any HTML tag that has a class of edit-text-NUM or edit-html-NUM and change the color of it. Here is what I am using...

jQuery(document).ready(function(){
    jQuery('*')
    .filter(function() {
        return this.className.match(/edit-(text|html)-\d/);
    })
    .css({
        'color': '#ff0000'
    });
});

Does that look ok and is the regex ok?

*edit: Also is this efficient? I am aware that using jQuery('*') might be a bit of a hog if it's a large page. It only has to work from <body> down so maybe it could be changed?

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery