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: “ +;





Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s