Ox.$: return undefined for non-existing attributes (like jQuery); fix a wrong 'this' reference

This commit is contained in:
rolux 2012-05-19 13:16:04 +04:00
parent f793245e2e
commit d3ff222a04

View file

@ -67,7 +67,7 @@ Ox.$ <f> Generic HTML element, mimics jQuery
> Ox.$('<div>').attr({id: 'red'}).attr('id')
'red'
> Ox.$('<div>').attr({id: 'red'}).removeAttr('id').attr('id')
''
void 0
> Ox.$('<div>').css({color: 'red'}).css('color')
'red'
> Ox.$('<div>').html('red').html()
@ -133,6 +133,9 @@ Ox.$ = Ox.element = function(val) {
var ret, that = this;
if (arguments.length == 1 && Ox.isString(arguments[0])) {
ret = this[0].getAttribute(arguments[0]);
if (ret === null) {
ret = void 0;
}
} else {
Ox.forEach(Ox.makeObject(arguments), function(v, k) {
that[0].setAttribute(k, v);
@ -254,8 +257,9 @@ Ox.$ = Ox.element = function(val) {
key <s> The attribute
@*/
removeAttr: function() {
var that = this;
Ox.makeArray(arguments[0]).forEach(function(key) {
this[0].removeAttribute(key);
that[0].removeAttribute(key);
});
return this;
},