Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript event listener get id of clicked items

// Create event listener
document.addEventListener('click', (e) =>
  {
    // Retrieve id from clicked element
    let elementId = e.target.id;
    // If element has id
    if (elementId !== '') {
        console.log(elementId);
    }
    // If element has no id
    else { 
        console.log("An element without an id was clicked.");
    }
  }
);
Comment

PREVIOUS NEXT
Code Example
Javascript :: monaco editor cdn 
Javascript :: hide an element when window resize css 
Javascript :: hover on child from parent mui react 
Javascript :: js addeventlistener keyup not working on phone 
Javascript :: dotenv in node js 
Javascript :: how to make html with jquery 
Javascript :: palindrome string js 
Javascript :: The element.appendChild() Method 
Javascript :: vue js data property in component must be a function 
Javascript :: javascript export multiple function 
Javascript :: react useeffect on change props 
Javascript :: react state not updating immediately 
Javascript :: mongoose search query for a word in a field 
Javascript :: await vuex dispatch true 
Javascript :: regex match between quotes without escape 
Javascript :: javascript compare timestamp 
Javascript :: blob to pdf javascript 
Javascript :: error message to show in label jquery 
Javascript :: next js typescript 
Javascript :: gatsby change page url 
Javascript :: expressjs param 
Javascript :: js opposite of startswith 
Javascript :: prisma where not in array 
Javascript :: batch react-redux 
Javascript :: recursive function javascript 
Javascript :: abstract class in js 
Javascript :: look behind regex 
Javascript :: react call bind apply 
Javascript :: make input bigger if text does not fit 
Javascript :: react usecallback hook 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =