Skip to content

Commit

Permalink
allow function argument to html
Browse files Browse the repository at this point in the history
  • Loading branch information
madrobby committed Jan 21, 2011
1 parent 04ff9c0 commit 890dc03
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.rdoc
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/zepto.js
Expand Up @@ -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 ?
Expand Down
13 changes: 13 additions & 0 deletions test/zepto.html
Expand Up @@ -460,6 +460,19 @@ <h1>Zepto DOM unit tests</h1>
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){
Expand Down

0 comments on commit 890dc03

Please sign in to comment.