Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript- send the clicked object as parameter in onClick function

In function clickCircle, i want to use the li which is being clicked. So i want to receive it as a parameter.

<li class="circle" onClick='clickCircle(this)'></li>

But what should i send as an actual paramenter? ie in place of 'this'.

like image 295
Aman Gupta Avatar asked Jan 19 '26 11:01

Aman Gupta


1 Answers

You can use this:

function clickCircle(obj) // the li element clicked in the current scope
{
    var element = obj;  // This is the DOM object being clicked
    var $this = $(obj); // This is the jQuery object being clicked

    // Use DOM object like
    element.style.color="#ff0000";

    // Use jQuery object like 
    $this.css('color', 'red');
}
like image 58
palaѕн Avatar answered Jan 21 '26 23:01

palaѕн



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!