Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

allow function argument to html

  • Loading branch information...
commit 890dc03fcecff4c5a947ee2b36f6853c5abe91b6 1 parent 04ff9c0
@madrobby authored
Showing with 16 additions and 1 deletion.
  1. +2 −0  README.rdoc
  2. +1 −1  src/zepto.js
  3. +13 −0 test/zepto.html
View
2  README.rdoc
@@ -57,6 +57,8 @@ Context and .find calls are equivalent:
remove(): remove element
html('new html'): set the contents of the element(s)
+ html(function(index, oldhtml){ return ...; }): set the contents of the element(s) from a method
+
text('new text'): set the text contents of the element(s)
append, prepend, before, after: like html(), but add html (or a DOM Element or a Zepto object) to element contents (or before/after)
html(): get first element's .innerHTML
View
2  src/zepto.js
@@ -106,7 +106,7 @@ var Zepto = (function() {
html: function(html){
return html === undefined ?
(this.length > 0 ? this.dom[0].innerHTML : null) :
- this.each(function(){ this.innerHTML = html });
+ this.each(function(idx){ this.innerHTML = typeof html == 'function' ? html(idx, this.innerHTML) : html });
},
text: function(text){
return text === undefined ?
View
13 test/zepto.html
@@ -460,6 +460,19 @@
t.assertEqual("", $('#htmltest3').html());
t.assertNull($('doesnotexist').html());
+
+ div.html('yowza');
+ div.html(function(idx, html){
+ return html.toUpperCase();
+ });
+ t.assertEqual('YOWZA', div.html());
+
+ div.html('<u>a</u><u>b</u><u>c</u>');
+
+ $('u').html(function(idx,html){
+ return idx+html;
+ });
+ t.assertEqual('<u>0a</u><u>1b</u><u>2c</u>', div.html());
},
testText: function(t){
Please sign in to comment.
Something went wrong with that request. Please try again.