Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Pass Element ID that Triggers `onclick` Event to the Event Handling Function

    • 0
    • 1
    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 6.34k
    Comment on it

    When we apply onclick event to an element, sometimes we need to pass ID of that element to the event handling function. We can do this by passing id to function as or we can pass the element itself.

    Example: In the below example I've created tow examples to pass element itself and only id.

     <!doctype html>
        <html lang="en">
        <meta charset="utf-8">
        <script src=""></script>
        <button id="startButton" onClick="checkElement(this);">Start</button>
        <button id="stopButton" onClick="checkId(;">Stop</button>
    	function checkElement (e) {
    	function checkId (id) {


    Hope this will help you :)

    In case any doubt please feel free to ask in comments below.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: