开发者

How to hide div that without id/class by jquery?

How to hide first/second div with jQuery?

Div can not get id/class!

<body>
<div>
<p>ssssssss</p>
</div>开发者_Python百科;
<div>
<p>ttttttttt></p>
</div>
<div>
<p>fffff</p>
</div>
</body>


To hide the first <div> element, do:

$("div:eq(0)").hide();

To hide the second <div> element, do:

$("div:eq(1)").hide();

To hide both the first and the second <div> elements, do:

$("div:lt(2)").hide();


$('div:lt(2)').hide();


$("body div:nth-child(1)").hide(); perhaps? untested

HTML markup is needed to help further

edit - ah ha, code block fail - my code still stands but i suspect there's a better way


You can use pseudo-selectors :first and :nth(n)... Note that nth(n) is zero-based. So :nth(0) is equivalent to :first.

$('div:first').hide();
$('div:nth(1)').hide();


to hide child div 1 and child div 2 (or 3 or 4)

   $('body div:nth-child(1),body div:nth-child(2)').hide();

nth-child is the offset and the comma seperates out which ones.. in case you wanted to keep div# 2 it could be

 $('body div:nth-child(1),body div:nth-child(3)').hide();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜