How to set width of a div in percent in JavaScript?

后端 未结 7 909
我寻月下人不归
我寻月下人不归 2020-12-09 08:09

Is it possible to set the height/width of an element in percent using JavaScript or jQuery?

7条回答
  •  春和景丽
    2020-12-09 08:52

    Also you can use .prop() and it should be better because

    Since jQuery 1.6, these properties can no longer be set with the .attr() method. They do not have corresponding attributes and are only properties.

    $(elem).prop('width', '100%');
    $(elem).prop('height', '100%');
    

提交回复
热议问题