1

I am trying to match a parent in the following HTML

<tbody> <tr id="group-1" class="group"> <td> <div class="GroupHeader"> Group1&nbsp;&nbsp;&nbsp;<span class="CriteriaEditOptions"><a id="EditGroupItem" href="/Template/EditGroupItem?GroupID=1">Edit</a></span>&nbsp;&nbsp; <span class="CriteriaMoveUp"><a href="/Template/GroupMovePosition?GroupID=1&amp;MoveType=0&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a></span>&nbsp;&nbsp; <span class="CriteriaMoveDown"><a href="/Template/GroupMovePosition?GroupID=1&amp;MoveType=1&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a></span> &nbsp;&nbsp;<span class="GroupDelete"><a href="/Template/DeleteGroup?GroupID=1&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a></span> </div> <table> <tbody> <tr id="1" class="selection"> <td> Number1&nbsp;&nbsp;&nbsp;<span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=1">Edit</a></span> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=1&amp;MoveType1=0&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=1&amp;MoveType1=1&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> &nbsp;&nbsp;<a href="/Template/DeleteCriteriaItem?CriteriaItemID=1&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a> </td> </tr> <tr id="2" class="selection"> <td> Price2&nbsp;&nbsp;&nbsp;<span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=2">Edit</a></span> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=2&amp;MoveType1=0&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=2&amp;MoveType1=1&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> &nbsp;&nbsp;<a href="/Template/DeleteCriteriaItem?CriteriaItemID=2&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a> </td> </tr> <tr id="3" class="selection"> <td> Single Line Text3&nbsp;&nbsp;&nbsp;<span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=3">Edit</a></span> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=3&amp;MoveType1=0&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=3&amp;MoveType1=1&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> &nbsp;&nbsp;<a href="/Template/DeleteCriteriaItem?CriteriaItemID=3&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a> </td> </tr> <tr id="4" class="selection"> <td> Single Line Text4&nbsp;&nbsp;&nbsp;<span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=4">Edit</a></span> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=4&amp;MoveType1=0&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=4&amp;MoveType1=1&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> &nbsp;&nbsp;<a href="/Template/DeleteCriteriaItem?CriteriaItemID=4&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a> </td> </tr> <tr id="5" class="selection"> <td> Single Line Text5&nbsp;&nbsp;&nbsp;<span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=5">Edit</a></span> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=5&amp;MoveType1=0&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=5&amp;MoveType1=1&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> &nbsp;&nbsp;<a href="/Template/DeleteCriteriaItem?CriteriaItemID=5&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a> </td> </tr> <tr id="6" class="selection"> <td> Number6&nbsp;&nbsp;&nbsp;<span class="CriteriaEditOptions"><a id="EditCriteriaItem" href="/Template/EditCriteriaItem?CriteriaID=6">Edit</a></span> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=6&amp;MoveType1=0&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Up</a> &nbsp;&nbsp;<a href="/Template/CriteriaItemMovePosition?CriteriaItemID=6&amp;MoveType1=1&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Down</a> &nbsp;&nbsp;<a href="/Template/DeleteCriteriaItem?CriteriaItemID=6&amp;rtn=http%253a%252f%252flocalhost%253a52724%252fTemplate%252fEditTemplate%253fCategoryID%253d6">Delete</a> </td> </tr> </tbody> </table> </td> </tr> </tbody> 

I am located at

<div class="GroupHeader"> 

And I am trying to match the parent at

<tr id="group-1" class="group"> 

is there a way to do this in jquery? I have tried using parent() but it didn't work

3 Answers 3

4

You can use closest('tr') to get the first parent that matches the supplied selector.

Sign up to request clarification or add additional context in comments.

1 Comment

+1, but shouldn't that be closest('tr.group') (just in case :) ?
2

.parents('tr') seeks upward

Comments

2

parent only looks one level up. Use parents to look multiple levels up.

$current.parents("#group-1 .group") 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.