I have a simple sidebar like this:
<div class="sidebar">
<ul class="nav">
<li class="Page1"><a href="Page1.html">Page1</a></li>
<li class="Page2"><a href="Page2.html">Page2</a></li>
<li class="Page3"><a href="Page3.html">Page3</a></li>
</ul>
</div>
This code exist on each one of the pages: page1.html, page2.html, page3.html.
On Page1.html, I would like Page1 not to be clickable.
On Page2.html, I would like Page2 not to be clickable.
On Page3.html, I would like Page3 not to be clickable.
Is that possible to do that without Javascript, i.e. pure HTML & CSS ? If not, what would be the easiest method to do that using Javascript, jQuery ?
If you want to do it purely with HTML and CSS, you have to generate a customized sidebar for each page.
However, if you dont mind using PHP, that shouldnt be much of a problem.
I'd actually recommend PHP for this, as it avoids possible usability/accessibility problems.
Another note: I wouldn't bother doing this anyway. On my website, I keep all links available - the title tells the user where she is anyway, so disabling links only creates trouble.
No, you need JavaScript, but you don't need jQuery.
Firstly, select the elements:
You need to convert the
NodeList
into anArray
. Use this function:Then... call
forEach
and check for the right link, disabling it:The best way to do it would be on the server side. In pseudocode that would look something like this
You could add
on the
<a>
tag that you want to disable.