if statement - jQuery get/toggle class and animate if -


still learing dem jqueries , found problem - wanted recreate classical feedback panel/slide side thing.

html

<div id="foobar" class="slide closed">             <img class="slidebutton" src="img/slide.png" alt="slide">              <div id="slidetext">                 <p>slide me out</p>             </div>     </div> 

jquery

$(document).ready(function() { $(".slidebutton").click(function () {     $('#foobar').toggleclass("open closed");      if $('#foobar').attr('class') returns 'closed' {         $( "#foobar" ).animate({ "left": "+=200px" }, "slow" );     }     else {         $( '#foobar' ).animate({ "right": "+=200px" }, "slow" );     }); });  }); 

if test toggle without if statement works assume made mistake considering animation?

infinite knowledge powers of ze interwebz welcome :)

you can use .hasclass() check if has class.

if($('#foobar').hasclass('closed')) {     $( "#foobar" ).animate({ "left": "+=200px" }, "slow" ); } else {     $( '#foobar' ).animate({ "right": "+=200px" }, "slow" ); } 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -