Hi there,
A quick fix is to modify your extension to:
jQuery.fn.toggleActive = function(){
$('#iconBox ul.bar li').children("a").removeClass("active");
$(this).addClass("active");
};
You would then call by:
$('#page2').click(function() {
($(this).children("a").toggleActive();
[...rest of code...]
return false;
});
Personally, if I was using extend, I'd try to make the function a
little more generic (instead of hardcoding id's etc). I'd also use the
'extend' functionality (http://docs.jquery.com/Core/
jQuery.fn.extend#object). Eg:
jQuery.fn.extend({
toggleActive: function() {
$(this).parent().children('a').removeClass('active');
$(this).addClass('active');
}
});
And you'd apply this by element instead of id:
$('#iconBox ul.bar li').children("a").click(function(){
$(this).toggleActive();
return false;
});
But use what works for you :)
On May 10, 9:56 am, Max <[EMAIL PROTECTED]> wrote:
> 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 wrote:
>
> jQuery.fn.toggleActive = function(e){
> $('#iconBox ul.bar li').children("a").removeClass("active");
> e.addClass("active");
> return false;
> };
>
> But I don't know how to call, and how to pass the param.
>
> Any help please?
>
> Thanks in advance.
>
> Max