开发者

I want to use a text string as my JQuery selector, how do I do that?

开发者 https://www.devze.com 2023-03-26 00:21 出处:网络
$(\"ul.tabs li\").click(function() { var tab = $(this).attr(\"id\"); var tabState = $开发者_开发技巧(this).is(\".selected\");
$("ul.tabs li").click(function() {
    var tab = $(this).attr("id");
    var tabState = $开发者_开发技巧(this).is(".selected");
    var showThis = ".selector-" + tab; 

    if (tabState == true) {
        $(NeedToConvertshowThisIntoObject).fadeIn(100);
    }
    else {
        alert(Something);
    }
});

Thanks!


You don't need to convert anything. The below line will work perfectly if the selector is matched.

$(showThis).fadeIn(100);


$(showThis) should do it:

$(showThis).fadeIn(100);


You can use $(showthis) instead $(NeedToConvertshowThisIntoObject) for example: $(showThis).fadeIn(100);

Best Regards Li Satisfy

0

精彩评论

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