javascript - Hide <li> without creating empty row - Stack Overflow

I am trying to hide a list item by using the following code (for example)<ol><li>Coffee<

I am trying to hide a list item by using the following code (for example)

<ol>
  <li>Coffee</li>
  <li style="visibility:hidden">Milk</li>
  <li>tea</li>
</ol>

But unfornately, it renders as follows with an empty row:

1. Coffee

3. Tea

What I want is simply like this:

1. Coffee
2. Tea

I am asking if there is a neat way to fix this? Thanks.

I am trying to hide a list item by using the following code (for example)

<ol>
  <li>Coffee</li>
  <li style="visibility:hidden">Milk</li>
  <li>tea</li>
</ol>

But unfornately, it renders as follows with an empty row:

1. Coffee

3. Tea

What I want is simply like this:

1. Coffee
2. Tea

I am asking if there is a neat way to fix this? Thanks.

Share Improve this question asked Apr 6, 2011 at 18:59 ZeigaZeiga 2014 silver badges14 bronze badges 2
  • I suppose <!-- <li>Milk</li> --> is out of the question? – Kaivosukeltaja Commented Apr 6, 2011 at 19:02
  • On what event is the list item meant to be removed/hidden? Is there some kind of logic behind it, or should it always be the second li? – David Thomas Commented Apr 6, 2011 at 19:08
Add a ment  | 

1 Answer 1

Reset to default 6

Use "display:none" instead of "visibility:hidden"

EDIT: visibility: hidden makes an element invisible but while keeping it in the flow of the DOM, so it still occupies the same space it would if it weren't invisible, meanwhile display: none treats it as if that element isn't there to begin with

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745113629a4611995.html

相关推荐

  • javascript - Hide &lt;li&gt; without creating empty row - Stack Overflow

    I am trying to hide a list item by using the following code (for example)<ol><li>Coffee<

    11小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信