0

I'm trying to do a toggle function on click. I don't understand why my function doesn't work, it's very simple...

http://jsfiddle.net/7y46W/1/

 $("#hello").toggle(function(){
 $('#content').css({marginLeft:'20px'});
     },function(){
 $('#content').css({marginLeft:'0px'});
 });
Damien
  • 333
  • 1
  • 3
  • 17

2 Answers2

0
$("#hello").on('click', function(){
    var toggle = $(this).data('toggle');  // get current state

    $('#content').css('margin-left', toggle ? 0 : 20);

    $(this).data('toggle', !toggle);      // set state to opposite of current
});                                       // state, i.e. a toggle switch

FIDDLE

adeneo
  • 312,895
  • 29
  • 395
  • 388
0

it does work... when you include jQuery. See fiddle.

included jQuery in framework selector.
R. Oosterholt
  • 7,720
  • 2
  • 53
  • 77