jquery - how to get <td> value from the closest different <tr> -
I'm closest & lt; Tr & gt; I'm trying to get the third text from
which contains only one & lt; Td> The text specified in one of the
text from the nearest / previous and lt; Tr & gt; The "cat" text is in
.
Click1 " is clicked, it should only be found near lion (preceding)
& lt; Table class = "animals" & gt; & Lt; TR & gt; & Lt; TD & gt; Cat & lt; / Td> & Lt; TD & gt; Dogs & lt; / Td> & Lt; TD & gt; Tiger & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Dog-1 & lt; / Td> & Lt; TD & gt; Dog-2 & lt; / Td> & Lt; TD & gt; Dog-3 & lt; / Td> & Lt; TD & gt; & Lt; A href = "#" square = "drop"> Click 1 & lt; / A & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Cat & lt; / Td> & Lt; TD & gt; Mouse & lt; / Td> & Lt; TD & gt; Horses & lt; / Td> & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Lion & lt; / Td> & Lt; TD & gt; Zebra & lt; / Td> & Lt; TD & gt; Camel & lt; / Td> & Lt; TD & gt; & Lt; A href = "#" square = "drop"> Click2 & lt; / A & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; TD & gt; Goat & lt; / Td> & Lt; TD & gt; Cow & lt; / Td> & Lt; TD & gt; Sheep & lt; / Td> & Lt; TD & gt; & Lt; A href = "#" square = "drop"> Click3 & lt; / A & gt; & Lt; / TD & gt; & Lt; / TR & gt; & Lt; / Table & gt;
& lt; Tr & gt;
and if "click2" , or "click3" is clicked, then it should only get horse Gives both "tiger" and "horse", whichever is clicked.$ ('. Drop'). Click (function () {var val = $ (this) closest ('Table'). ('Tr: includes ("cat").) (' Td: eq (2) '). Text (); Alert (val);});
= "Text">
$ (this) .closest ('table'). ('Tr': ('' cat ''): lt ('+ $ (this) .clostest (' tr ') .index () +'): last ') (' TD: eq (2) ' ) Text () ;.
jsFiddle:
Comments
Post a Comment