How to set $(this) as the clicked element

Multi tool use
up vote
-1
down vote
favorite
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?
javascript jquery
add a comment |
up vote
-1
down vote
favorite
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?
javascript jquery
1
this
appears to indeed refer to the clicked element? jsfiddle.net/eqh36m0r
– CertainPerformance
2 days ago
as per jquery documentation api.jquery.com/delegate this actually is clicked element, why don't you just use it instead of set?
– Just code
2 days ago
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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?
javascript jquery
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?
javascript jquery
javascript jquery
asked 2 days ago
David542
31.8k89243442
31.8k89243442
1
this
appears to indeed refer to the clicked element? jsfiddle.net/eqh36m0r
– CertainPerformance
2 days ago
as per jquery documentation api.jquery.com/delegate this actually is clicked element, why don't you just use it instead of set?
– Just code
2 days ago
add a comment |
1
this
appears to indeed refer to the clicked element? jsfiddle.net/eqh36m0r
– CertainPerformance
2 days ago
as per jquery documentation api.jquery.com/delegate this actually is clicked element, why don't you just use it instead of set?
– Just code
2 days ago
1
1
this
appears to indeed refer to the clicked element? jsfiddle.net/eqh36m0r– CertainPerformance
2 days ago
this
appears to indeed refer to the clicked element? jsfiddle.net/eqh36m0r– CertainPerformance
2 days ago
as per jquery documentation api.jquery.com/delegate this actually is clicked element, why don't you just use it instead of set?
– Just code
2 days ago
as per jquery documentation api.jquery.com/delegate this actually is clicked element, why don't you just use it instead of set?
– Just code
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
up vote
3
down vote
accepted
This is more of clarification rather than answer.
this
is already referring to the currently clicked element.
$(document).on("click", ".match-item", function(event) {
console.log($(this).attr('class'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
Parent
<div class="match-item">----Click Me</div>
</div>
Probably better to ask for clarification or VTC as no-repro
– CertainPerformance
2 days ago
add a comment |
up vote
0
down vote
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
It's after the page load so that wouldn't work.
– David542
2 days ago
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
accepted
This is more of clarification rather than answer.
this
is already referring to the currently clicked element.
$(document).on("click", ".match-item", function(event) {
console.log($(this).attr('class'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
Parent
<div class="match-item">----Click Me</div>
</div>
Probably better to ask for clarification or VTC as no-repro
– CertainPerformance
2 days ago
add a comment |
up vote
3
down vote
accepted
This is more of clarification rather than answer.
this
is already referring to the currently clicked element.
$(document).on("click", ".match-item", function(event) {
console.log($(this).attr('class'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
Parent
<div class="match-item">----Click Me</div>
</div>
Probably better to ask for clarification or VTC as no-repro
– CertainPerformance
2 days ago
add a comment |
up vote
3
down vote
accepted
up vote
3
down vote
accepted
This is more of clarification rather than answer.
this
is already referring to the currently clicked element.
$(document).on("click", ".match-item", function(event) {
console.log($(this).attr('class'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
Parent
<div class="match-item">----Click Me</div>
</div>
This is more of clarification rather than answer.
this
is already referring to the currently clicked element.
$(document).on("click", ".match-item", function(event) {
console.log($(this).attr('class'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
Parent
<div class="match-item">----Click Me</div>
</div>
$(document).on("click", ".match-item", function(event) {
console.log($(this).attr('class'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
Parent
<div class="match-item">----Click Me</div>
</div>
$(document).on("click", ".match-item", function(event) {
console.log($(this).attr('class'));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="parent">
Parent
<div class="match-item">----Click Me</div>
</div>
edited 2 days ago
answered 2 days ago
Mamun
21.3k71428
21.3k71428
Probably better to ask for clarification or VTC as no-repro
– CertainPerformance
2 days ago
add a comment |
Probably better to ask for clarification or VTC as no-repro
– CertainPerformance
2 days ago
Probably better to ask for clarification or VTC as no-repro
– CertainPerformance
2 days ago
Probably better to ask for clarification or VTC as no-repro
– CertainPerformance
2 days ago
add a comment |
up vote
0
down vote
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
It's after the page load so that wouldn't work.
– David542
2 days ago
add a comment |
up vote
0
down vote
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
It's after the page load so that wouldn't work.
– David542
2 days ago
add a comment |
up vote
0
down vote
up vote
0
down vote
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
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
answered 2 days ago


Bonish Koirala
3437
3437
It's after the page load so that wouldn't work.
– David542
2 days ago
add a comment |
It's after the page load so that wouldn't work.
– David542
2 days ago
It's after the page load so that wouldn't work.
– David542
2 days ago
It's after the page load so that wouldn't work.
– David542
2 days ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53184052%2fhow-to-set-this-as-the-clicked-element%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
2hX4kNNkqB0yDmYB,NkNrl7Psg4fF8poSQ lqEMhjJGsS,5C2JHXcaHv dQkfAdfr,3IuoAmTQgHj iz7X Fcwg1
1
this
appears to indeed refer to the clicked element? jsfiddle.net/eqh36m0r– CertainPerformance
2 days ago
as per jquery documentation api.jquery.com/delegate this actually is clicked element, why don't you just use it instead of set?
– Just code
2 days ago