I've written a function that works fine, but being new to jQuery, I'd like some reviews on writing this more cleanly. Anything advice would help; just trying to learn!
function displayContent() {
var $link1 = $('.row.nav li a.bio');
var $link2 = $('.row.nav li a.stylist');
var $link3 = $('.row.nav li a.contact');
var $content = $('#text-content')
var $bio = $("#bio");
var $stylist = $("#stylist");
var $contact = $("#contact");
var $overlay = $('.content-overlay');
//link1
$link1.click(function (e) {
e.stopPropagation();
$link2.removeClass('active');
$link3.removeClass('active');
$link1.addClass('active');
$contact.hide();
$stylist.hide();
$bio.fadeIn(700);
$overlay.show();
});
//link2
$link2.click(function (e) {
//same code here
});
//link3
$link3.click(function (e) {
//same code here
});
//close overlay/hide content
$('html').click(function (e) {
//hide code
});
}
// same code here
does that mean that both of those handlers are identical? – cookie monster Feb 28 '14 at 4:06