[jQuery] Right way to write a function
Hi everybody,
I'm new on jQuery and I wanted to know which is the correct way to
right a function. For example I have a menu-list, and I want to clear
the "selected" state of all elements, and set it to the selected
element. So I wrote thi function:
function toggleActive(e){
$('#iconBox ul.bar li').children("a").removeClass("active");
e.addClass("active");
return false;
}
And I invoke with:
$('#page1').click(function() {
toggleActive($(this).children("a"));
[...rest of code...]
return false;
});
$('#page2').click(function() {
toggleActive($(this).children("a"));
[...rest of code...]
return false;
});
This works.
But I think this is not the "jQuery sintax", so I'm triying to do it
right.
So I