The following is my code for comments pagination.
<ul class="pager">
<li class="previous">
<a href="#">Older Comments ←</a>
</li>
<li class="next">
<a href="#">Newer Comments →</a>
</li>
</ul>
My problem is if I'm on the first page of comments (and older comments link is hidden), an empty list item is displayed in the DOM.
<li class="previous">
</li>
<li class="next">
<a href="#">Newer Comments →</a>
</li>
In a semantic way should I remove the empty list item (1) or leave it there empty (2)?
<ul class="pager">
<li class="next">
<a href="#">Newer Comments →</a>
</li>
</ul>
<ul class="pager">
<li class="previous">
</li>
<li class="next">
<a href="#">Newer Comments →</a>
</li>
</ul>
Which option is correct in a semantic way?
I have a better suggestion to use a disabled state:
<ul class="pager">
<li class="previous">
<a href="#" class="disabled">Older Comments ←</a>
</li>
<li class="next">
<a href="#">Newer Comments →</a>
</li>
</ul>
Also I have another idea, if you are completely getting rid of CSS. Instead of <a>
tags, you can use <button>
or <input type="button" />
, as even in Facebook, the same thing is used. So, you can style the <button>
tag to look like <a>
tag and give a disabled state, as this works even when both JavaScript and CSS is disabled.
<ul class="pager">
<li class="previous">
<button disabled="disabled">Older Comments ←</button>
</li>
<li class="next">
<button>Newer Comments →</button>
</li>
</ul>
For styling <button>
as <a>
:
/* Just for this demo */
ul, li {margin: 0; padding: 0; list-style: none; display: inline-block;}
button {border: none; background: none; color: #00f; text-decoration: underline; cursor: pointer;}
button:disabled {color: #999; cursor: default;}
<ul class="pager">
<li class="previous">
<button disabled="disabled">Older Comments ←</button>
</li>
<li class="next">
<button>Newer Comments →</button>
</li>
</ul>
The above code works in all browsers, including Internet Explorer! :)
here's short and sweet.. :)
<style type="text/css">
a.disabled {
pointer-events: none;
cursor: default;
color:#999;
}
</style>
<ul class="pager">
<li class="previous">
<a class="disabled" href="#">Older Comments ←</a>
</li>
<li class="next">
<a href="#">Newer Comments →</a>
</li>
</ul>
GOOD LUCK!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With