How to set $(this) as the clicked element

918 views javascript

In the following code:

// submit an item
$(document).on("click", ".match-item", function(event) {

    // how to set $(this) == $('.match-item') clicked?


I'm looking to retrieve $(this) as the clicked item and not the document itself. How would I do this?

answered question

this appears to indeed refer to the clicked element?

Why do you want to use $(this) instead of $( You can't change the value of this inside the function.

as per jquery documentation this actually is clicked element, why don't you just use it instead of set?

2 Answers


This is more of clarification rather than answer.

this is already referring to the currently clicked element.

$(document).on("click", ".match-item", function(event) {
<script src=""></script>
<div class="parent">
  <div class="match-item">----Click Me</div>

posted this

How about

$('.match-item').click(function() {
     //your code with $(this) here

I am pretty sure $(this) will refer to the element with class match-item

posted this

Have an answer?


Please login first before posting an answer.