henryaaron
henryaaron

Reputation: 6192

Closest Table of The Closest Table

My Question is how can I select the .closest('table') of the .closest('table').

I tried:

$('div').closest('table').closest('table').hide();

and it didn't work, is there a way to select the closest table of the closest table?

Upvotes: 0

Views: 2059

Answers (3)

user9410037
user9410037

Reputation:

You can put an ID at the first table:

<table id="firstTable">
$('div').closest('#firstTable').hide();

Upvotes: 0

Adil
Adil

Reputation: 148150

Dot missing before first closest

Live Demo

$('div').closest('table').closest('table').hide();

Upvotes: 2

Kevin B
Kevin B

Reputation: 95027

You could use .parents for this:

$('div').parents('table').eq(1).hide();

0 would be closest, 1 second closest, 2 third closest, etc.

Upvotes: 4

Related Questions