javascript - I'm trying to toggle the top margin of a div on click. -


i'm trying shift div it's initial position top margin of 22em 0 when clicked. every other click should revert 22em.

html

<div id="container3" class="isdown"> <div class="test" id="name3">  </div>   </div> 

css

.test{margin-top: 22em;} 

jquery

$("#container3").click( function(event){     event.preventdefault();     if ($(this).hasclass("isdown") ) {         $("#name3").animate({margintop:"0em"});                   $(this).removeclass("isdown");     } else {         $("#name3").animate({margintop:"22em"});            $(this).addclass("isdown");     }     return false; }); 

sorry if it's mess. have no idea i'm doing!

try toggleclass css class like

style

.test{margin-top: 22em;} 

script

$("#container3").click( function(event){     event.preventdefault();     $("#name3").toggleclass('test');               $(this).toggleclass("isdown");        return false; }); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -