hi Scott,

Cheers..thats pretty cool.  One more thing actually..I need the element to
be a div..how do I add this to the selector..I actually managed to write
something using recursion yesterday but its pretty nasty..i would much
prefer to use something like what you've give me.

function findClass(el) {
                var $myel = $(el).prev();
                var $class = ''
                if ($myel.is('div')) {
                        if ($myel.attr('class') == '') {
                                $class = findClass($myel);
                        } else {
                                $class = $myel.attr('class');
                        }
                } else {
                        $class = findClass($myel);
                }
                return $class;
        }

thanks for your help



Scott Sauyet-2 wrote:
> 
> 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
> 
> 

-- 
View this message in context: 
http://old.nabble.com/previous-tp26678777s27240p26690836.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.

Reply via email to