aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/jqLite.js9
-rw-r--r--test/jqLiteSpec.js32
2 files changed, 41 insertions, 0 deletions
diff --git a/src/jqLite.js b/src/jqLite.js
index 6d42bbc2..d7faa1e8 100644
--- a/src/jqLite.js
+++ b/src/jqLite.js
@@ -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/)
@@ -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
diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js
index 0ebb1717..a7fded5c 100644
--- a/test/jqLiteSpec.js
+++ b/test/jqLiteSpec.js
@@ -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(){