javascript - toggle with hasClass -


i trying use hasclass on toggle , cant find example want. basically, button toggles class , forth.

here code:

$("#sidebar-toggle-btn").click(function() {   $("#sidebar").toggle();   if($('#mapdiv').hasclass('col-lg-6')) {     $('#mapdiv').removeclass('col-lg-6');     $('#mapdiv').addclass('col-lg-8');   };   if($('#mapdiv').hasclass('col-lg-8')) {     $('#mapdiv').removeclass('col-lg-8');     $('#mapdiv').addclass('col-lg-6'); }); 

example: http://jsfiddle.net/monduiz/dzo5yg72/

hsz , tushar offered right suggestions. reason wasn't working because idiot. trying apply toggle wrong button in interface. works:

$("#projects-btn").click(function() {   $('#sidebar').toggle();   $("#mapdiv").toggleclass('col-lg-6 col-lg-8'); }); 

just try .toggleclass('col-lg-6 col-lg-8'):

$("#sidebar-toggle-btn").click(function() {   $("#sidebar").toggle();   $("#mapdiv").toggleclass('col-lg-6 col-lg-8'); }); 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -