Will checking the width
attribute be sufficient to make sure my DOM element has a striclty positive width or should I also check for css rules (I am only looking for elements that have a fixed number of pixels as a CSS rule, no % width).
if (element.offsetWidth && element.offsetWidth > 0) // do stuff
OR
if ((element.offsetWidth && element.offsetWidth > 0)
|| (element.style && element.style.width
&& int(element.style.width.replace("px", ""), 10)>0 ) // do stuff
I would rather go for the first one but I want to make sure that setting the CSS rule will also set the width
attribute.
---- EDIT ----
Actually offsetWidth
seems to be better than width
in any case. I changed width
to offsetWidth
.
Does it make the second option (checking for the CSS) worthless?
element.offsetWidth
should suffice - and no, checking the style
element will not be necessary
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다