javascript - Selecting just one the closest element -


I have a problem selecting the closest element using jQuery.

My HTML code

  & lt; Table & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; TD & gt; & Lt; Span class = "control" & gt; & Lt; Img class = "doAction" & gt; & Lt; / Span & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; Td square = "description" & gt; Some time ago & lt; / Td> & Lt; / TR & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; After clicking on the image  .doAction  

I want to get the text from .details . But the problem is that I have the same HTML code many times, so I want to get it near img .details text.

How can I do this?

You can also use it

  $ ( 'DoAction'). ('Click', function () {console.log ($ (this) .parents ('tr'). Next (). Description '). Text ());});  

Here, select tr with the img tag with the class I .doAction and then going to next tr and .details

Note that This . Parent (s) , if you want you to . You can also use Parent () , but then you have to use it three times, such as

  $ (this). Parent (). Parent (). Parent (). Next () Find ('details'). Text (); / * - ^ - - ^ - - ^ - - ^ - The SPAN TD trail goes to the next trunk and then again. Searches for and returns text * /  

Comments