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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -