onclick javascript pass this object

Below is demo html which will show you how to pass this object to javascript function and get id of it:

<html>
<head>
<meta charset="ISO-8859-1">
<title>onclick javascript pass this object</title>
<script type="text/javascript">

function testing(value) {	
	document.getElementById(value.id);
	alert(value.id);	

}
</script>
</head>
<body>

<input type="text" name="test" id="test" onclick="testing(this)">

</body>
</html>

Leave a Reply

Your email address will not be published. Required fields are marked *