javascript - Trying to apply classes on a click event using JS -



javascript - Trying to apply classes on a click event using JS -

i'm new javascript , have used primary post how toggle classes here: change element's css class javascript reason code not executing expect to. code placed in bottom of html file.

<script> $(document).ready(function () { $('.arrow').addeventlistener('click', function() { if (this.hasclass('glyphicon-chevron-right')) { this.addclass('glyphicon-chevron-left'); this.removeclass('glyphicon-chevron-right'); } if (this.hasclass('glyphicon-chevron-left')) { this.addclass('glyphicon-chevron-right'); this.removeclass('glyphicon-chevron-left'); } }, false); }); </script>

set click listener , utilize .toggleclass() instead of if clauses:

$('.arrow').on('click', function() { $(this).toggleclass('glyphicon-chevron-right'); $(this).toggleclass('glyphicon-chevron-left'); });

or more succinctly

$('.arrow').on('click', function() { $(this).toggleclass('glyphicon-chevron-right glyphicon-chevron-left'); });

javascript jquery

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -