I can use this
to get the id from my clicked button, but I cannot select the clicked button with this
to run my setTimeout function.
$(".btn").click(function () {
var userChosenColour = $(this).attr("id");
$(this).addClass("pressed");
setTimeout(function() {$(this).removeClass("pressed");} , 100);
})
However, I can run it in this way by not using this
:
$(".btn").click(function () {
var userChosenColour = $(this).attr("id");
$(this).addClass("pressed");
setTimeout(function() {$("#" + userChosenColour).removeClass("pressed");} , 100);
})
Do I have any misconception on the keyword this
?