user3001408
user3001408

Reputation: 310

How to Modify Elements from JQuery Click Event

I have a link like this:

 <a class="search_res_click" target="_blank" href="#">
 <div>
  // lot of stuff here
 </div>

 </a>

And I attached an event to all such links via following:

$(".search_res_click").click(function(e) {
    $(".search_res_click").children().css("opacity", "1");
    $(e).css("opacity", "0.5");
    console.log($(e));
});

The function of the event handler is to change the opacity of the clicked link. But when I am clicking on the link it is not changing the opacity.

Could you please tell me what I am doing wrong here.

Upvotes: 1

Views: 35

Answers (1)

Oleksandr T.
Oleksandr T.

Reputation: 77482

Try this

$(this).css("opacity", "0.5");

or

$(e.currentTarget).css("opacity", "0.5");

because e is object not element

Upvotes: 5

Related Questions