ANSWERSGO.com

Added new notification system!, Receive a notification alerting you about actions on your questions and answers. Report any bug in meta Thanks



1

Answers

 

1

Stars

jQuery/JavaScript - get clicked button itself in a function

Asked By : GeekyCoder10 Front End Dev

I need a way to get the element pressed in a function called by that element

I tried using $(this), but is not working




1 Answers



2

Stars

  

You can pass this in your onclick function like this

 
    //Javascript
    function x(obj){
        alert($(obj).attr("id"));
    }
    //onclick function on button
    onclick='x(this)' 

with this you can see the ID of buttons in alert, pass this instance to function and create Jquery object from it.

.


- Ahmed Ali ♦ 2020-07-21 17:46:04

Add Comment

 

It worked! Thanks works like a charm - GeekyCoder10


My pleasure - Ahmed Ali ♦


Testing comment - Ahmed Ali ♦




Question Comments:

Feel free to discuss about question, here!