Problem:
Within a click event for another DOM element, you wish to alter the class of a TD element based on its unique ID ("td_id").
Solution with jQuery:
To set the class outright, use the .attr() method:
$("#td_id").attr('class', 'newClass');
To add a class without affecting existing ones, use .addClass():
$("#td_id").addClass('newClass');
For a quick class swap, try .toggleClass():
$("#td_id").toggleClass('change_me newClass');
Additional Class Manipulation Methods:
The above is the detailed content of How Can I Change a TD's Class Using jQuery Based on Its ID?. For more information, please follow other related articles on the PHP Chinese website!