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
Post a Comment