-2
rated 0 times
[
2]
[
4]
/ answers: 1 / hits: 27365
/ 12 Years ago, thu, december 6, 2012, 12:00:00
I am passing a DOM object after an onclick event occurs and I need to know the id of the element I've passed from the html. I've read about the this.id
that exists in JavaScript but I cannot seem to utilize it correctly.
Here is my code in the function:
function clickFunction() {
$(.tictactoe).on('click', function() {
$(this).text(X);
if (this.id == upleft) {
$('#upright').text(yes);
}
});
}
$(document).ready(function() {
$('#playagain').hide();
$('.tictactoe').on(click);
clickFunction();
});
So I thought that my quick test, if successful, would present the word yes in the grid of a tic tac to bar in the upper right corner when I clicked the position on the left.
Perhaps there is something wrong with my comparison?
this.id == upright
The X's show up, indicating the rest of the code works, so it must be the comparison. Let me know your thoughts.
More From » jquery