Friday, 23 August 2013

Making sure DOM element has positive width

Making sure DOM element has positive width

Will checking the width attribute be sufficient to make sure my DOM
element has a positive width or should I also check for css rules (I am
only looking for element that have a fixed number of pixels as a CSS rule,
not %).
if (element.width && element.width > 0) // do stuff
/** ---- or ---- */
if ((element.width && element.width > 0)
|| (element.css && element.css.width
&& int(element.css.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.

No comments:

Post a Comment