Alkarin Alkarin - 5 months ago 25
CSS Question

document.getElementById("className").className Cannot set property 'className' of null

I'm trying to find an element with the class "active" and change its class to "inactive".

Currently I'm getting this error

Cannot set property 'className' of null


document.getElementById("active").className = "inactive";


<a href="javascript:;" class="paginationlink active" data-page-number="1"></a>

I don't believe the issue is because I have two classes because I have tried removing the
from the element and I still return the same error.

I have looked at a similar issue here and here but I do not have an Id attribute to pull from that would be unique.


The problem is that you're getting the element using document.getElementById("active") but there is not id="active" defined. Try adding an id="active"