javascript - How to select element by id within existing selection? -
given html:
<div id="div-a"></div> <div id="div-b"></div> <div id="div-c"></div> and previously-created jquery selection:
var $divs = $("div"); how can select particular div in selection id?
note: $divs selection has not yet been appended dom, can't select directly (e.g. $("#div-b")).
find() selects descendants of selection, not work:
$divs.find("#div-b"); has() / :has() selects elements contain element specified selector, not work:
$divs.has("#div-b");
you want use filter() reduce set/.
var elem = $divs.filter("#div-b");
Comments
Post a Comment