I have a menu with links. The links are placed inside a table. Each link is placed in a
Your current code is That will change all tds in the table. Instead use To make the other ones revert back, use the . I want to change the background color of the
$(function() {
$("#mainMenu td").click(function() {
$("#mainMenu td").css('background-color', '#EDEDED');
});
});
$(this)
inside your function to select the element that triggered the click event.$(function() {
$("#mainMenu td").click(function() {
$(this).css('background-color', '#EDEDED');
});
});
siblings()
selector to select all tds except the clicked one.$(function() {
$("#mainMenu td").click(function() {
$(this).css('background-color', '#EDEDED')
.siblings().css('background-color', '#FFFFFF');
});
});