Setting a boolean attribute with jquery

后端 未结 3 1157
离开以前
离开以前 2021-01-17 10:40

I understand that jquery will allow you to modify attributes with the .attr() method. There are basically two methods:

$(\'#element\').attr(\'attribute\', \'         


        
3条回答
  •  失恋的感觉
    2021-01-17 11:40

    I use this method in jQuery

    jQuery('option').attr("selected", "");
    

    or in JavaScript:

    document.querySelector("option").setAttribute("selected", "");
    

    It's just you need to pass an empty string to just set boolean attribute.

提交回复
热议问题