admin管理员组文章数量:1331662
im just wondering if what I want to do is possible with jQuery...
I have the following...
<ul class="navmenu">
<li>Something</li>
<li>Something</li>
<li>Someting</li>
<li>Something</li>
</ul>
What i want to do is display:none; the first LI within .navmenu, is this possible?
im just wondering if what I want to do is possible with jQuery...
I have the following...
<ul class="navmenu">
<li>Something</li>
<li>Something</li>
<li>Someting</li>
<li>Something</li>
</ul>
What i want to do is display:none; the first LI within .navmenu, is this possible?
Share edited Dec 23, 2011 at 15:13 graphicdivine 11.2k7 gold badges35 silver badges59 bronze badges asked Dec 23, 2011 at 15:10 LiamLiam 9,85540 gold badges114 silver badges214 bronze badges 1- 4 Sure, have lot ways to do that, try to read the docs api.jquery./category/selectors even google can answer that for you... – Gabriel Gartz Commented Dec 23, 2011 at 15:15
6 Answers
Reset to default 3Just use:
$('.navmenu > li:first-child').hide();
jsFiddle Example.
You also may want to check out the jQuery Tutorials and jQuery Selectors API Docs as this is a pretty basic usage of jQuery.
<sarcasm>
No, you can't do it. Ever.</sarcasm>
$('.navmenu li:first').hide()
CSS Solution (this should prevent the first element from flickering on page load):
.navmenu > li:first-child {display: none;}
sure,
$('ul.navmenu li:first').css('display', 'none');
You can use a descendant selector, >
, to select the li
children of the ul
with the navmenu
class name, then use the first-child
pseudo class to select just the first one. Then you can set css styles using the css
method:
$("ul.navmenu > li:first-child").css("display", "none")
Live example: http://jsfiddle/uDeQE/1/
Yep, certainly is:
$('.navmenu li:first')
You could also user the pseudo selector in CSS if its styling you're after:
.navmenu li:first-child
本文标签: JavaScriptJQueryDisplay none first LI in ULStack Overflow
版权声明:本文标题:javascript - jQuery, Display none first LI in UL - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742265801a2443367.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论