Using jQuery, how do you match elements that are prior to the current element in the DOM tree? Using prevAll() only matches previous siblings.<
prevAll()
I usually number elements (1,2,3..) (rel="number"), so then i use this code to give class to all previous elements:
var num = $(this).attr("rel"); for (var i = 1; i<=num; i++) { $('.class[rel="'+i+'"]').addClass("newclass"); }