how to get id of any control using javascript? -


i have html page various textbox , button

then added javascript

window.onload = function () {   window.addeventlistener('click', function (evt) {     alert(this.id);   }, false); }; 

my goal return id of control clicked user (as alert)? add more this. alert ok now. thank you

use target of event. here's runnable sample:

window.onload = function () {    window.addeventlistener('click', function (evt) {      alert(evt.target.id);    }, false);  };
<input id="button" type="button" value="button" />  <input id="text" type="text" />


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

java - Openshift port-forwarding -

php - Symfony 2: "No route found for "GET /" - error on fresh installation -