Remove multiple attributes with jQuery's removeAttr

前端 未结 2 1311
-上瘾入骨i
-上瘾入骨i 2021-02-02 05:12

I have the following code.

$(document).ready(function(){
 $(\'#listing img\')
 .attr(\'width\', 250)
 .removeAttr(\'height\').removeAttr(\'align\').removeAttr(\'         


        
相关标签:
2条回答
  • 2021-02-02 05:17

    Yes :

    .removeAttr('height align style')
    

    From the documentation :

    as of version 1.7, it can be a space-separated list of attributes.

    0 讨论(0)
  • 2021-02-02 05:23

    Yes, you can remove it in that way:

    $('#listing img').removeAttr('height align style');
    

    you can also add those attributes as follows:

    $('#listing img').attr({ height: "20", align: left }).css({ color: red, text-align: center });
    
    0 讨论(0)
提交回复
热议问题