Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

css(property,'') removes the style as in jquery - both usage cases #467

Merged
merged 1 commit into from

3 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 4, 2012
  1. @gregorymostizky @hardbap
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 4 deletions.
  1. +14 −4 src/zepto.js
  2. +7 −0 test/zepto.html
View
18 src/zepto.js
@@ -439,10 +439,20 @@ var Zepto = (function() {
: this[0].style[camelize(property)] || getComputedStyle(this[0], '').getPropertyValue(property)
)
}
- var css = ''
- for (key in property) css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';'
- if (typeof property == 'string') css = dasherize(property) + ":" + maybeAddPx(property, value)
- return this.each(function(){ this.style.cssText += ';' + css })
+ var css = '';
+ for (key in property) {
+ if(typeof property[key] == 'string' && property[key] == '')
+ this.each(function() {this.style.removeProperty(dasherize(key))});
+ else
+ css += dasherize(key) + ':' + maybeAddPx(key, property[key]) + ';';
+ }
+ if (typeof property == 'string') {
+ if (value == '')
+ this.each(function() {this.style.removeProperty(dasherize(property))});
+ else
+ css = dasherize(property) + ":" + maybeAddPx(property, value);
+ }
+ return this.each(function() { this.style.cssText += ';' + css });
},
index: function(element){
return element ? this.indexOf($(element)[0]) : this.parent().children().indexOf(this[0])
View
7 test/zepto.html
@@ -1090,6 +1090,13 @@
var div = $('#get_style_element')
t.assertEqual('48px', div.css('font-size'))
t.assertEqual('rgb(0, 0, 0)', div.css('color'))
+
+ $('#some_element').css('color', '')
+ t.assertEqual('', el.style.color)
+
+ $('#some_element').css({'margin-top': '', 'marginBottom': ''})
+ t.assertEqual('', el.style.marginTop)
+ t.assertEqual('', el.style.marginBottom)
},
testCSSOnNonExistElm: function (t) {
Something went wrong with that request. Please try again.