admin管理员组文章数量:1299983
I would like to know how could I write a jQuery selector that get all children from a parent element except first and last child?
Example of my current HTML:
<div id="parent">
<div>first child( i don't want to get)</div>
<div>another child</div>
<div>another child</div>
<div>another child</div>
(...)
<div>another child</div>
<div>another child</div>
<div>last child (i dont want to get neither)</div>
</div>
I would like to know how could I write a jQuery selector that get all children from a parent element except first and last child?
Example of my current HTML:
<div id="parent">
<div>first child( i don't want to get)</div>
<div>another child</div>
<div>another child</div>
<div>another child</div>
(...)
<div>another child</div>
<div>another child</div>
<div>last child (i dont want to get neither)</div>
</div>
Share
Improve this question
edited Dec 28, 2010 at 17:25
DVK
130k33 gold badges218 silver badges334 bronze badges
asked Dec 28, 2010 at 17:24
CleitonCleiton
18.2k13 gold badges47 silver badges59 bronze badges
3
- 2 It's a good idea to spell check your questions so they look more professional and not like you are a slacker who doesn't care. – DVK Commented Dec 28, 2010 at 17:26
- DVK, I'm sorry, but I don't speak english as first language, I will try to be more carefull. – Cleiton Commented Dec 28, 2010 at 17:28
- most modern web browsers have built-in spell checkers. I never pick on people's English, only on really obvious typos (as non-English-native-speaker, it's very easy for me to know which one's which :) – DVK Commented Dec 28, 2010 at 17:36
6 Answers
Reset to default 11Like this:
$('#parent > div:not(:first, :last)');
You can do this:
$('#parent div').not(':first').not(':last')
Or
$('#parent').children().not(':first').not(':last')
Here not
method will filter out first and last elements from the selector.
More Information:
- http://api.jquery./not/
$('#parent').children(':not(:first):not(:last)')
$('#parent').children().not(':first').not(':last')
Should work
$("#parent > div:not(:first, :last)");
Try this:
$(
function()
{
var a = $("div#parent *:not(:first-child)").not(":last-child");
alert(a.length);
}
)
本文标签: javascriptGet child elements from a parent but not first and lastStack Overflow
版权声明:本文标题:javascript - Get child elements from a parent but not first and last - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741640754a2389902.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论