You might want to change the structure of your plugin definition to something like this
$.fn.menuWidth = function(options) {
this.show = function() {
this.animate({
width: 400
});
return this; // <---- This will enable chaining
};
this.hide = function() {
return "hide";
};
return this; // <--- returning this will make visible the hide and show methods.
};
console.log($("#header").menuWidth().show().hide());
Doing jQuery's show and hide is also possible but this might sound a bit like a hack.
$($("#header").menuWidth().show()).hide();
menuWidth plugin returns this which is the instance of the element. Wrapping it into a jQuery object will let us perform .hide() and .show().
This will not be possible if .hide() of menuWidth is invoked because it does not return the element instance.
PS: This is a very very simple way to write a plugin. There are better and much more complex ways to write plugins.
$.fn.menuWidth = function(options) {
this.show = function() {
this.animate({
width: 400
});
return this;
};
this.hide = function() {
return "hide";
};
return this;
};
console.log($("#header").menuWidth().show().hide());
#header{
width: 100px;
border: 1px solid red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="header">
This is a header
</div>
thiswhich allows them to be chainable. Not hard to find lots of tutorials on jQuery plugins