Skip to content

Commit

Permalink
Add removeAttr method (issue kupriyanenko#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
kupriyanenko committed Oct 11, 2014
1 parent 93509de commit 27e31bb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ $.when(deferred).then(function(response) {
* [.attr(attributeName)](https://github.com/kupriyanenko/jbone/wiki/Attributes#attrattributename)
* [.attr(attributeName, value)](https://github.com/kupriyanenko/jbone/wiki/Attributes#attrattributename-value)
* [.attr(attributes)](https://github.com/kupriyanenko/jbone/wiki/Attributes#attrattributes)
* [.removeAttr(attributeName)](https://github.com/kupriyanenko/jbone/wiki/Attributes#removeattrattributename)
* [.val()](https://github.com/kupriyanenko/jbone/wiki/Attributes#val)
* [.val(value)](https://github.com/kupriyanenko/jbone/wiki/Attributes#valvalue)
* [.css(propertyName, value)](https://github.com/kupriyanenko/jbone/wiki/Attributes#csspropertyname-value)
Expand All @@ -141,6 +142,8 @@ $.when(deferred).then(function(response) {
* [.data(obj)](https://github.com/kupriyanenko/jbone/wiki/Data#dataobj)
* [.data(key)](https://github.com/kupriyanenko/jbone/wiki/Data#datakey)
* [.data()](https://github.com/kupriyanenko/jbone/wiki/Data#data)
* [.removeData(key)](https://github.com/kupriyanenko/jbone/wiki/Data#removedatakey)
* [.removeData()](https://github.com/kupriyanenko/jbone/wiki/Data#removedata)

[Event](https://github.com/kupriyanenko/jbone/wiki/Event)

Expand Down
11 changes: 11 additions & 0 deletions src/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ fn.attr = function(key, value) {
return this;
};

fn.removeAttr = function(key) {
var i = 0,
length = this.length;

for (; i < length; i++) {
this[i].removeAttribute(key);
}

return this;
};

fn.val = function(value) {
var i = 0,
length = this.length;
Expand Down
13 changes: 13 additions & 0 deletions test/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,19 @@ describe('jBone Attributes', function() {
expect(a.attr('target')).to.be('_blank');
});

it('removeAttr(key) should remove attribute', function() {
var $el = jBone('<div>');
$el.attr('name', 'value');
$el.removeAttr('name');
expect($el.attr('name')).to.be(null);
});

it('removeAttr(key) should works correct if attr is not exist', function() {
var $el = jBone('<div>');
$el.removeAttr('name');
expect($el.attr('name')).to.be(null);
});

it('val() getting value', function() {
var a = jBone('<input>');
a[0].value = 'test';
Expand Down

0 comments on commit 27e31bb

Please sign in to comment.