开发者

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜