Handling multiple IDs in jQuery

后端 未结 2 630
温柔的废话
温柔的废话 2020-12-13 08:22

Can multiple ids be handled like in the code?



2条回答
  •  情深已故
    2020-12-13 08:41

    Solution:

    To your secondary question

    var elem1 = $('#elem1'),
        elem2 = $('#elem2'),
        elem3 = $('#elem3');
    

    You can use the variable as the replacement of selector.

    elem1.css({'display':'none'}); //will work

    In the below case selector is already stored in a variable.

    $(elem1,elem2,elem3).css({'display':'none'}); // will not work

提交回复
热议问题