Bug Tracker

Opened 12 years ago

Closed 12 years ago

#2193 closed bug (invalid)

toggle( FunctionA reference to a Javascript function. evenThe function to execute on every even click., FunctionA reference to a Javascript function. oddThe function to execute on every odd click. )

Reported by: windark Owned by:
Priority: major Milestone: 1.2.3
Component: core Version: 1.2.2
Keywords: Cc:
Blocked by: Blocking:

Description

my code: $(document).ready(function(){

$('#btn_tog').click(function(){

$("li").toggle(

function () {

alert('1');

}, function () {

alert('2');

});

});

});

this code can't alert the message when i click the button.my jquery version is 1.2.2.

Change History (1)

comment:1 Changed 12 years ago by scott.gonzal

Resolution: invalid
Status: newclosed

The posted code is not setup to alert on a button click. It is setup to alert when the user clicks on an li element, after clicking the button.

$(document).ready(function(){
    // this sets up a click event on the element with id "btn_tog"
    $('#btn_tog').click(function(){
        // this sets up a click event on all li elements
        $("li").toggle(
            function () {
                alert('1');
            }, function () {
                alert('2');
            });
    });
});

Your example is unclear about what your desired behavior is, but you probably wanted something more like:

$('#btn_tog').toggle(
    function() {
        alert('even');
    },
    function() {
        alert('odd');
    }
);
Note: See TracTickets for help on using tickets.