开发者

Changing a class with a variable as the id in jQuery?

开发者 https://www.devze.com 2023-01-11 05:58 出处:网络
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.

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");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消