Share Coding

Tutorials, Problems, Stuffs …

Select excetly parent

Basically, this is the jQuery basic selector to select a html object.

$('#btnSubmit')

 

How to select a parent?

$('#btnSubmit').parent() // my parent
$('#btnSubmit parent') // my top parent

 

But browser will add <tbody> to our <table>, so that we can’t select excetly parent by

$('#btnSubmit').parent().parent().parent().parent().parent()

 

Solution:

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

Select the closest table parent, you may use class to instead table

Advertisements

One response to “Select excetly parent

  1. Ripped Muscle Xtreme 2013/04/29 at 2:55 am

    Hi there! This post couldn’t be written much better! Reading through this article reminds me of my previous roommate! He constantly kept talking about this. I will forward this information to him. Pretty sure he’ll have a
    great read. Thank you for sharing!

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: