$.prev("div.a").find('.b').
$.prev("div.a .b").
One works and the other does not. What’s the difference?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Well, the selector works, it just doesn’t give you what you want:
According to jQuery Docs
.prev([expr]):This means:
$(elem).prev("div.a").find('.b')is looking for any previous sibling in the DOM Tree that is adiv.aand returning the first – then search within that element using.find()for a.bWhereas:
$(elem).prev("div.a .b")is looking for any previous sibling that is adiv.a .band returning the first.They are not equivalent and therefore return different results.