javascript - How to implement a generic click event for anchors -


currently have php script throws out bunch of buttons(format in case needed is

<a class="classinfo" id="id">name</a> 

the file retrieved dynamically , there can many buttons possible, maybe none , maybe million(unlikely though). anyways javascript. need use javascript , cant redirect user website(mostly because operation repeated heavily , gets extremely tedious..).

is possible me use combination of javascript + jquery detect button pressed , operation appropriately?

example of hoping this: user clicks 1 of buttons(which has unique id number). javascript detects button clicked(i cant use fixed code number of buttons , ids can change whenever feel it). javascript send out ajax request , fancy operations(i got part covered).

now possible me detect button clicked? struggling this.

the target property of event object tell element clicked on.

document.addeventlistener('click', function (e) {   var target = e.target;   if (target.tagname && target.tagname.tolowercase() == "a") {     alert(target.id);   } }); 

see a live demo


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -