Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

how to check in js if element is li or is button

// use attribute .tagName, which returns a type e.g. DIV, BUTTON, LI etc.
const functionName = () => {
	if(e.target.tagName == 'BUTTON') {
    console.log("It's a button";
	} else {
	    console.log("It's not a button");
	}
}

// if you prefer: function functionName (params) {action} instead of "e.target" use this
 
PREVIOUS NEXT
Tagged: #check #js #element #li #button
ADD COMMENT
Topic
Name
1+3 =