jQuery/Javascript css(“width”) / check if style is defined in css?

后端 未结 4 682
慢半拍i
慢半拍i 2020-12-17 15:26

I have a stylesheet which defines default width for images. When I read the image width style with jQuery width() it returns the right width. It also returns th

4条回答
  •  盖世英雄少女心
    2020-12-17 15:49

    You can check the element's style.cssText if the width is defined;

    
    
    var pic = document.getElementById('pic');
    alert(pic.style.cssText);
    

    ​But please note of the following styles

    border-width: 10px;
    width: 10px;
    

    you should only match the width not the border-width.

提交回复
热议问题