How to change jQuery toggle() status

Posted by Zier Gofren Schlanum on Stack Overflow See other posts from Stack Overflow or by Zier Gofren Schlanum
Published on 2010-05-27T11:41:15Z Indexed on 2010/05/27 11:51 UTC
Read the original article Hit count: 118

Filed under:
|
|

Using toogle to show/hide the div, I've got a problem that when I hide my div with anothor function, I have to click twice on the button to perform correct action.

Is there any way change the toggle switch like I clicked the button?

$('#add_task').toggle(function() { 
    if ($("#new_task_status").attr("value")==0) { 
        $("#new_task").slideDown();
        $("#new_task_status").attr("value", "1");
    }
}, function() {
    if ($("#new_task_status").attr("value")==1) { 
        $("#new_task").slideUp();
        $("#new_task_status").attr("value", "0");
    }
});


$('nav').click(function() { 
    if ($("#new_task_status").attr("value")==1) { 
        $("#new_task_status").attr("value", "0");
        $("#new_task").slideUp();
    }
});

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery