メソッドを使用して.data()
、元の html http://jsfiddle.net/94nPv/3/を保存できます。
jQuery(document).ready(function($) {
$('h5').toggle(function() {
var $this = $(this);
$this.data('originalText',$this.html());
$this.parent('div.softwarebox').animate({ height: "700px" });
$this.html("Close");
}, function() {
var $this = $(this);
$this.parent('div.softwarebox').animate({ height: "19px" });
$this.html($this.data('originalText'));
});
});
わずかに最適化されています (.html または .data への余分な呼び出しはありません): http://jsfiddle.net/94nPv/7/
jQuery(document).ready(function($) {
$('h5').each(function(){
var $this = $(this);
$this.data('originalText',$this.html());
});
$('h5').click(function() {
var $this = $(this);
if ($this.text() === "Close") {
$this.html($this.data('originalText'));
$this.parent('div.softwarebox').animate({
height: "19px"
});
}
else {
$this.text("Close");
$this.parent('div.softwarebox').animate({
height: "700px"
});
}
});
});