biquillo
biquillo

Reputation: 6539

finding a div parent element with a certain property

When my slider moves I have to catch the id of the div containing data-role="page"

<div data-role="page" data-theme="a" id="buttons"> 
   <div data-role="content"> 
    <label for="slider1">Slider 1</label>
    <input type="range" name="slider1" id="slider1" value="0" min="0" max="100"  /> 
   </div> 
</div> 

And then when the slider event triggers I execute this:

console.log($(this).find("div").filter('[data-role=page]').attr("id")); 

but doesn't work. Any ideas? Thanks in advance!

Upvotes: 1

Views: 782

Answers (1)

gen_Eric
gen_Eric

Reputation: 227280

Try .closest if this is a child of the div you want:

console.log($(this).closest('div[data-role="page"]').attr("id")); 

Upvotes: 3

Related Questions