Forum How do I...?

Add and remove CSS classes using javascript

ronniecmc
Hello, I'm stuck trying to add a class {display: none} to a div to make sure the elements on that page do not print. The goal is to maintain a consistent format with a photo on the left page, and a table on the right. When the table is too long, however, every following page shifts to have the photo on the right and the table on the following left page. By adding {display: none}, I've been able to prevent the image on the long table from printing, thus maintaining a consistent layout.

Using javascript, I've been able to pull the ID of the element that I'd like to target, but when I try to add a class -- removePic.classList.add("remove-pic"), I get this error in the CLI: test-layout.html:76: error: TypeError: undefined value is not an object.

If there is a better way to dynamically remove pages, I'm all ears.

Any help is appreciated!
mikeday
Prince doesn't support classList, but you can use removePic.className = "remove-pic";
ronniecmc
This worked! Thank you so much.