JavaScript   

Pure JavaScript click event listener

This is code snippet is for adding JavaScript click events on multiple elements with the same class name.

HTML Code 

<button class="add-product">Add</button>
<button class="add-product">Add</button>
<button class="add-product">Add</button>
<button class="add-product">Add</button>

JS Code 

let productAddBtns=document.getElementsByClassName("add-product");

for (var i = 0; i < productAddBtns.length; i++) {
    productAddBtns[i].addEventListener('click', addProduct, false);
}

function addProduct(){
  console.log("add product Clicked");
}

This is code snippet is for adding a JavaScript click event on the single element ID.

HTML Code 

<button id="show-product">Add</button>

JS Code

let productShowBtn=document.getElementById("show-product");

productShowBtn.onclick = function(){
showProduct();
};

function showProduct(){
  console.log("show product Clicked");
}

 

Need Professional Support for Your Website Problems?

Whether you're facing website issues or struggling with code implementation, our team is here to assist. Hire us to get your website back on track.

Hire Us

Got an idea? We'll turn it into reality.

Tell us what you're building, what's broken, or what numbers need to move. We'll come back within one business day with a short plan — no long decks, no sales calls without purpose.

Response time: First reply within 1 business day on 100% of messages.
Transparent scope: Fixed proposals with weekly check-ins & live task tracking.
Ship-ready builds: Every engagement leaves behind documented, transferable work.
Long-term partners: Ongoing retainers for support, SEO, ads, and content.