Changing a class with a variable as the id in jQuery?
Hey all, I am not quite getting why this doesn't seem to be working. The alert pops out the correct id, but the removeClass does not seem to be firing. What am I doing wrong开发者_如何学C?
function testClassSwitch(t_id) {
alert("Do things to a button with this ID: " + t_id);
$(t_id).removeClass("add-button");
}
Thanks!
Does your t_id
have the #
id selector on it?
add #
before the id like this
function testClassSwitch(t_id) {
alert("Do things to a button with this ID: " + t_id);
$('#' + t_id).removeClass("add-button");
}
精彩评论