Custom jQuery plugin to manipulate tabs

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml”&gt;
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Jquery Custom Plugin</title>
http://code.jquery.com/jquery-1.10.1.min.js

(function ($){
$.fn.Tabs = function (options){
var settings = $.extend({
color : “#000000”,
background : “#ffffff”,
container : ”,
dafault : 1
}, options );

this.css({
‘color’: settings.color,
‘background-color’: settings.background
});

$(“#”+settings.container).ResetAll();

$(‘#c’+settings.dafault).show();
$(‘#’+settings.dafault).css( “color”, “red” );

$(this).children(“a”).on(‘click’, function() {
$(“#”+settings.container).ResetAll();
$(‘#c’+$(this).attr(“id”)).fadeIn(“slow”);
$(this).css( “color”, “red” );
});

};

$.fn.ResetAll = function() {
$(this).children(“div”).hide();
this.find( “a” ).css( “color”, “black” );
};

}(jQuery));

$( document ).ready(function() {
$( “#test” ).Tabs({
color: “#000000”,
background: ‘#cccccc’,
container: ‘test’,
dafault : 1
});
});

<style>
.cont{
width:400px;
padding:10px;
border:1px solid #000000;
}
.cont a{
text-decoration: none;
background-color:#FFFFFF;
border:2px solid #000000;
padding:2px;
}
</style>

</head>
<body>

Tab 1
Tab 2
Tab 3

In addition, the primary purpose of an Immediately Invoked Function is to allow us to have our own private variables. Pretend we want a different color green, and we want to store it in a variable.
It’s good practice when writing plugins to only take up one slot within $.fn. This reduces both the chance that your plugin will be overridden, and the chance that your plugin will override other plugins. In other words, this is bad.
.pagerLink {
background-color: #E4F5F8;
border: 1px solid #C0DEED;
text-decoration: none !important;
}

</div>

other 1
other 2
other 3

</body>
</html>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s