[jQuery] function with jQuery-like syntax -- how/when to use
I did some searching on the group on this subject and found some
things, but not exactly what I'm looking for.
I don't understand how/when to use $.functionname = function() {}
Here is what I have, which gives me the error "$.setActive is not a
function". If I write this as a standard function (function
setActive() {}) it works fine. What am I doing wrong?
if ( $("div#wrapper").is(".list") ) {
$.setActive("span#list-view");
$("div.thread").each(function() {
$(this).addClass("new").addClass("collapsed")
});
} else { // explicit else if (exp) fails. Unknown reason.
$.setActive("span#expanded-view");
$("div.thread").each(function() {
$(this).addClass("new").addClass("expanded");
});
};
$.setActive = function(tab) {
//sets active
if ( ! $(tab).is(".active") ) {
$(this).addClass("active");
};
//Make sure there are not multiple "active" tabs
if ( ($(".tabs span.active").length) > 1 ) {
$(".tabs span.active").each(function() {
if ( ! $(this).is(tab) ) {
$(this).removeClass("active");
};
});
};