I have this HTML code
<td>
<div><p> My Txt </p></div>
<div><a class="linkclass" >link1 </a><a> link2 </a></div>
</td>
Now i want that if someone click on a.linkclass
then i alert the text inside p tag
I tried this but it didn't work
$(this).closest('p').text();
Try this
$(this).closest('div').prev('div').find('p').text();
Here p is not the ancestor of the anchor tag.. Is is nested inside a div.. So you cannot use the .closest()
on the p tag directly..
The closest selector only traverses thru the ancestors of the element...
EDIT
You can also use the closest on the td directly.
$(this).closest('td').find('p').text();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With