How to set $(this) as the clicked element

Multi tool use
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?










share|improve this question


















  • 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















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?










share|improve this question


















  • 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













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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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














  • 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












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>








share|improve this answer























  • Probably better to ask for clarification or VTC as no-repro
    – CertainPerformance
    2 days ago


















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






share|improve this answer





















  • It's after the page load so that wouldn't work.
    – David542
    2 days ago











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















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
































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>








share|improve this answer























  • Probably better to ask for clarification or VTC as no-repro
    – CertainPerformance
    2 days ago















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>








share|improve this answer























  • Probably better to ask for clarification or VTC as no-repro
    – CertainPerformance
    2 days ago













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>








share|improve this answer














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>






share|improve this answer














share|improve this answer



share|improve this answer








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


















  • 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












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






share|improve this answer





















  • It's after the page load so that wouldn't work.
    – David542
    2 days ago















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






share|improve this answer





















  • It's after the page load so that wouldn't work.
    – David542
    2 days ago













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






share|improve this answer












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







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









Bonish Koirala

3437




3437












  • 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




It's after the page load so that wouldn't work.
– David542
2 days ago


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














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




















































































2hX4kNNkqB0yDmYB,NkNrl7Psg4fF8poSQ lqEMhjJGsS,5C2JHXcaHv dQkfAdfr,3IuoAmTQgHj iz7X Fcwg1
b M,ZS,n4,U,jmAWyJjur

Popular posts from this blog

横浜市

Rostock

Europa