I want to be able to click on an element and then depending on whether it has a specific class name, do something.
Here is what I have so far:
<div class="my-class" onclick="myFunction()"/>
function myFunction() {
if (element.classList.contains("my-class")) {
//do something
}
}
where am I going wrong?
class, notclassname?elementwhere do you declare it?elementdoes not get set in your code. Usefunction myFunction ( eve ) { if (eve.target.classList.contains .....