Reputation: 15274
My html structure is like below :
<header></header>
<div id="take-113"></div>
<div id="take-114"></div>
<div id="take-115"></div>
How can I find same header from each div?
$("take-113").prev("header"); // works
$("take-114").prev("header");// doesn't work
$("take-115").prev("header"); // doesn't work
Upvotes: 1
Views: 63
Reputation: 6617
$("take-113").prev("header"); // works
$("take-114").prev("header");// doesn't work
$("take-115").prev("header"); // doesn't work
replace this by
$("#take-113").prev("header");
$("#take-114").prev("header");
$("#take-115").prev("header");
Upvotes: -1
Reputation: 6320
if you have more then one header then you can define which one you want to get
$("take-113").prevAll("header:first");
$("take-114").prevAll("header:first");
$("take-115").prevAll("header:first");
Upvotes: 0
Reputation: 144689
prev
only selects the previous sibling of the element, you can use prevAll()
method:
$("#take-114").prevAll("header").first();
Upvotes: 2