i've searcherd for answers but i didn't find nothing.. so please if you think this is a duplicate tell me and i'll remove it, thanks.
When i write something like body.classList.add("someExampleClass");
the console gives me that Uncaught TypeError: Cannot read property 'add' of undefined
. I've added the CDN
//cdnjs.cloudflare.com/ajax/libs/classlist/2014.01.31/classList.min.js
but it keeps the error, i've tried with Chrome and Safari.
That's the full code:
HTML
<svg height="35" width="35" id="rect1" class="" onmouseover="over()">
<rect width="35" height="35"/>
</svg>
JS
function over() {
$('p').classList.add("purple");
}
Thanks in advance to all and have a good day.
p
-tag in your HTML. When do you call yourover()
function? MaybeclassList
-js is not loaded yet?