开发者

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开发者_JAVA技巧? Thanks in advance!


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜