Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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 select every elements which their width CSS property is 750px for example in a single selector?

EDIT: If there is no such selector, is there any plugin, or any plans to do it in the next jQuery versions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
212 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...