How to get parent element by specified tag name using jquery? -


i want element's parent has specified tag name.

sample code:

<table>    <tr>       <td>           <input type='button' id='myid' />       </td>    </tr> </table> 

now want this:

$('#myid').specificparent('table'); //returns nearest parent of myid element table it's tagname. 

see .closest():

get first ancestor element matches selector, beginning @ current element , progressing through dom tree.

i.e.,

$('#myid').closest('table') 

(demo)


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

aspxgridview - Devexpress grid - header filter does not work if column is initially hidden -

c# - How to execute a particular part of code asynchronously in a class -