How to use JavaScript variables in jQuery selectors?

前端 未结 6 1674
天涯浪人
天涯浪人 2020-11-21 22:38

How do I use JavaScript variables as a parameter in a jQuery selector?



        
6条回答
  •  情歌与酒
    2020-11-21 23:26

    var name = this.name;
    $("input[name=" + name + "]").hide();
    

    OR you can do something like this.

    var id = this.id;
    $('#' + id).hide();
    

    OR you can give some effect also.

    $("#" + this.id).slideUp();
    

    If you want to remove the entire element permanently form the page.

    $("#" + this.id).remove();
    

    You can also use it in this also.

    $("#" + this.id).slideUp('slow', function (){
        $("#" + this.id).remove();
    });
    

提交回复
热议问题