Skip to content

Commit

Permalink
Add $.fn.text
Browse files Browse the repository at this point in the history
  • Loading branch information
sstephenson committed Nov 30, 2010
1 parent ae36734 commit e3737aa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/zepto.js
Expand Up @@ -56,6 +56,11 @@ var Zepto = (function() {
(this.dom.length>0 ? this.dom[0].innerHTML : null) :
this.each(function(el){ el.innerHTML = html });
},
text: function(text){
return text === un ?
(this.dom.length>0 ? this.dom[0].innerText : null) :
this.each(function(el){ el.innerText = text });
},
attr: function(name,value){
return (typeof name == 'string' && value === un) ?
(this.dom.length>0 ? this.dom[0].getAttribute(name) || undefined : null) :
Expand Down
16 changes: 16 additions & 0 deletions test/zepto.html
Expand Up @@ -25,6 +25,9 @@ <h1>Zepto DOM unit tests</h1>
<div class="htmltest" id="htmltest2"></div>
<div id="htmltest3"></div>

<div id="texttest1" class="texttest"><span>Here <strong>is</strong> some text</span></div>
<div id="texttest2" class="texttest">And <em>some more</em></div>

<div id="beforeafter_container"><div id="beforeafter"></div></div>

<p id="find1">
Expand Down Expand Up @@ -324,6 +327,19 @@ <h1>Zepto DOM unit tests</h1>
t.assertNull($('doesnotexist').html());
},

testText: function(t){
t.assertEqual('Here is some text', $('div.texttest').text());
t.assertEqual('And some more', $('#texttest2').text());

$('div.texttest').text("Let's set it");
t.assertEqual("Let's set it", $('#texttest1').text());
t.assertEqual("Let's set it", $('#texttest2').text());

$('#texttest2').text('');
t.assertEqual("Let's set it", $('div.texttest').text());
t.assertEqual('', $('#texttest2').text());
},

testBind: function(t){
var counter = 0;
$(document.body).bind('click', function(){ counter++ });
Expand Down

0 comments on commit e3737aa

Please sign in to comment.