简体   繁体   中英

jQuery: effect of setting CSS property to empty string as opposed to setting it to none?

I've seen the following code:

$(this).css('border-color', '');

and wonder whether it is the same as:

$(this).css('border-color', 'none');

or whether in the first case the border-color CSS property is simply reset to its default value from the CSS stylesheet (and if not, then is there a way to reset the value to whatever is default in the stylesheet?). My concern is that I shouldn't have to change the jQuery JavaScript when I change the border-color in the stylesheet. Things should happen automatically.

Setting the css value to none is literally setting it to none in css. Setting it to an empty string removes the property from the style attribute on the tag.

<div style="border-color: none;"></div>

vs

<div style></div>

The reason you'd use none is if you want to overwrite an existing style that sets border-color to something. If you remove the style from the style attribute then it will fall back to an already defined style for border-color if it exists.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM