Get Source Element on OnClick Event Raised

While developing web applications we don’t know the id of the control many times (mostly when controls are added dynamically ) .In JavaScript we can get the control and its properties on On Click event of the control.

 HTML Code

 

<button name=’<%# Eval (“ProductName”) %> value=”Open” onclick=”javascript:test();”>Open</button>

 Javascript Code

<script type=”text/javascript” language=”javascript”>function test(){
 

var tag;

tag=“Element name: “ + window.event.srcElement.tagName + ” ID: “ + window.event.srcElement.id;

document.write(tag);

}

 </script>

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s