javascript - How to toggle between 2 icons -


i have toggle between 2 icons based on criteria. how do in jquery?

<a href='' id="home" onclick="myfunction(this)" data-toggle="toggle">     <span class="fa fa-train"></span> </a> 
myfunction($this) {     // ...      if ($($this).hasclass("fa fa-train")) {         $($this).removeclass("fa fa-train");         $($this).addclass("fa fa-car");     }     else {         $($this).addclass("fa fa-car");         $($this).addclass("fa fa-train");     }      // ... } 

do this

 $('a#home').on('click', function(){    var childspan = $(this).find('span');    if(childspan.hasclass('fa-train')){      childspan.removeclass('fa-train');      childspan.addclass('fa-car');    }    else if(childspan.hasclass('fa-car')){     childspan.removeclass('fa-car');     childspan.addclass('fa-train');    }}); 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -