Is there a style selector in jQuery?

前端 未结 5 1243
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 10:27

If I want to select every image which it\'s alt is Home for example, I can do something like this:

$(\"img[alt=\'Home\']\")

But how can I s

5条回答
  •  时光取名叫无心
    2020-11-30 10:49

    Not necessarily a great idea, but you could add a new Sizzle selector for it :

    $.expr[':'].width = function(elem, pos, match) {
        return $(elem).width() == parseInt(match[3]);
    }
    

    which you could then use like so:

    $('div:width(970)')
    

    That's going to be horrifically slow, though, so you'd want to narrow down on the number of elements you're comparing with something like :

    $('#navbar>div:width(970)')
    

    to only select those divs that are direct descendants of the navbar, which also have a width of 970px.

提交回复
热议问题