Javascript object using "this"
I'm learning javascript. I want to try creating a simple object for
hiding/showing some blocks of text, so I wrote this code.
var Post = {
init: function(el){
this.el = el;
this.title = el.children(".title");
this.entry = el.children(".entry");
var that = this;
this.title.on("click", function(){
that.hide();
});
},
hide: function(){
this.entry.slideUp('fast');
},
show: function(){
this.entry.slideDown('fast');
}
}
$(".post").each(function(){
Post.init($(this));
})
http://jsfiddle.net/ZVpau/
And the problem is, that this code is always hiding only last post, no
matter what title you have clicked on. Can anyone tell me where is the
problem?
No comments:
Post a Comment