首页 > 解决方案 > 检查 style="height: 0px"

问题描述

我有一些元素通过脚本分配了内联样式高度。我需要检查一个元素是否具有以下内容:style="height: 0px"

<div class="myEm" style="height: 30px">...</div>
<div class="myEm" style="height: 10px">...</div>
<div class="myEm" style="height: 0px">...</div>

jQuery

$(".myEm").each(function(){
   if ($(this).attr("style") == "0px") {
      $(this).css("border-color", "red");
   }
});

https://jsfiddle.net/p9nfskeL/1/

标签: javascriptjquery

解决方案


以下作品:

$(".myEm").each(function() {
  if (this.style.height == "0px") {
    $(this).css("border-color", "red");
  }
});

推荐阅读