-2

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

javascript:

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

html:

<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 paginationlink 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.

Community
  • 1
  • 1
Alkarin
  • 464
  • 7
  • 20
  • 1
    the getElementById function will give you the DOM object having as id "active" meanwhile you're not having it you have a class active not an id – PacMan Sep 03 '16 at 00:16
  • When you set `.className` it will replace *all* the classes. So you'll lose the `paginationlink` class. You should use `.classList.add('inactive')` – Barmar Sep 03 '16 at 00:21

1 Answers1

0

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"

Enmanuel Duran
  • 4,988
  • 3
  • 17
  • 29