On Dec 7, 10:23 am, lennon1980 <ja...@publiczone.co.uk> wrote: > I want to find all previous elements in the DOM (not parent elements) of > element called 'feature' [ ... ] > But I want to find all previous divs that have a css class assinged to them. > the first previous div it finds I want to be able to retrieve the class name > of that dic in a string.
Will this do what you want?: var item = $("#feature").prevAll("[class]:first"); if (item) alert(item.attr("class")); You can pass a selector into prevAll. Here we select only those elements that contain an attribute named "class" and then choose just the first one of these. ('First' here does not mean document order but something more like 'closest'.) Cheers, -- Scott