[jQuery] Get the previous element matching a class

2010-03-02 Thread debussy007

Hi, 

I would like to have the previous TD element with class time. 

I tried : $(this).closest('td').prev('td.time').html()   (where this is a
div element inside a TD) 
But it only works for a div inside a TD that is *directly* following the
td.time element. 

See the code below: my jquery selector above is only working for the div's
inside td class=lun01032010 (where the latter is directly following
td.time element), 
not for the div's inside td class=mar02032010 

td class=time 
8am 
/td 
td class=lun01032010 
div class=quarter daylun /div 
div class=quarter daylun /div 
div class=quarter daylun /div 
div class=quarter daylun /div 
/td 
td class=mar02032010 
div class=quarter daymar /div 
div class=quarter daymar /div 
div class=quarter daymar /div 
div class=quarter daymar /div 
/td 

Thank you for any help. 
мэтт
-- 
View this message in context: 
http://old.nabble.com/Get-the-previous-element-matching-a-class-tp27757091s27240p27757091.html
Sent from the jQuery General Discussion mailing list archive at Nabble.com.



Re: [jQuery] Get the previous element matching a class

2010-03-02 Thread Nathan Klatt
On Tue, Mar 2, 2010 at 9:20 AM, debussy007 debussy...@gmail.com wrote:
 I would like to have the previous TD element with class time.

 I tried : $(this).closest('td').prev('td.time').html()   (where this is a
 div element inside a TD)
 But it only works for a div inside a TD that is *directly* following the
 td.time element.

Yeah, prev only gets the immediately preceding sibling; prevAll gets
all previous siblings so I think you want something like this:

$(this).closest('td').prevAll('td.time').last().html()

Nathan