Reputation: 1043
How does PubSub really works? Suppose I have a button that can show or hide an specific div. If I open the same URL in different windows or tabs, I want the events to sync. I have not done this before and PubSub is a tad bit scary. Is there like a stand-alone Library for it without installing lots of packages? Can you guys point me to the right direction and please don't not just say "Google It Up" because that's why I am doing for the last 5 hours.
$(document).on("click", ".mybutton", function () {
if ($(".mydiv").hasClass("hide")) {
$(".mydiv").removeClass("hide").show();
}
});
Upvotes: 0
Views: 89
Reputation: 722
You mean this?
var evt = {};
$(document).on("click", ".mybutton", function () {
$(evt).trigger('buttonClick');
});
$(evt).on('buttonClick',function(){
if ($(".mydiv").hasClass("hide")) {
$(".mydiv").removeClass("hide").show();
}
});
Upvotes: 1