JQuery: search previous div
4 answers
As long as I understand a few selectors correctly, this should work. It will get all divs with class 'a' and and span with id 'b'. They will be โdocumentedโ in accordance with the documentation . Then you need to get the div before your span tag and display it.
var elems = $('span#b, div.a'); var divIndex; for (var i = 0; i < elems.length; i++) { if (elems[i].tagName == "SPAN") { divIndex = i - 1; break; } } $(elems[divIndex]).show(); 0