Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

Commit

Permalink
feat(jqLite): add prop() support
Browse files Browse the repository at this point in the history
since jQuery 1.6.4 prop() became very important because attr() does't have access to certain properties any more (e.g. className), so I'm adding it to jqLite as well so that jqLite preserves the feature-set it had before the jQuery upgrade.
  • Loading branch information
IgorMinar committed Sep 16, 2011
1 parent 009059d commit 3800d17
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/jqLite.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
* - [eq()](http://api.jquery.com/eq/)
* - [hasClass()](http://api.jquery.com/hasClass/)
* - [parent()](http://api.jquery.com/parent/)
* - [prop()](http://api.jquery.com/prop/)
* - [remove()](http://api.jquery.com/remove/)
* - [removeAttr()](http://api.jquery.com/removeAttr/)
* - [removeClass()](http://api.jquery.com/removeClass/)
Expand Down Expand Up @@ -287,6 +288,14 @@ forEach({
}
},

prop: function(element, name, value) {
if (isDefined(value)) {
element[name] = value;
} else {
return element[name];
}
},

text: extend((msie < 9)
? function(element, value) {
// NodeType == 3 is text node
Expand Down
32 changes: 32 additions & 0 deletions test/jqLiteSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,38 @@ describe('jqLite', function(){
});


describe('prop', function() {
it('should read element property', function() {
var elm = jqLite('<div class="foo">a</div>');
expect(elm.prop('className')).toBe('foo');
});

it('should set element property to a value', function() {
var elm = jqLite('<div class="foo">a</div>');
elm.prop('className', 'bar');
expect(elm[0].className).toBe('bar');
expect(elm.prop('className')).toBe('bar');
});

it('should set boolean element property', function() {
var elm = jqLite('<input type="checkbox">');
expect(elm.prop('checked')).toBe(false);

elm.prop('checked', true);
expect(elm.prop('checked')).toBe(true);

elm.prop('checked', '');
expect(elm.prop('checked')).toBe(false);

elm.prop('checked', 'lala');
expect(elm.prop('checked')).toBe(true);

elm.prop('checked', null);
expect(elm.prop('checked')).toBe(false);
});
});


describe('class', function(){

describe('hasClass', function(){
Expand Down

0 comments on commit 3800d17

Please sign in to comment.