1 Replies - 429 Views - Last Post: 08 June 2016 - 08:52 AM

#1 bb8   User is offline

  • D.I.C Regular

Reputation: 7
  • View blog
  • Posts: 335
  • Joined: 31-January 16

toggleClass()

Posted 08 June 2016 - 08:39 AM

this is a simple code that should toggle change the icons color when clicking it, i click the icon a few times then it changes its color but literally after 1 second the page kinda refreshes and the color is the old one (even though i didn't click the icon). what's wrong?

html:
<a href="" id="location"><i class="fa fa-map-marker"></i></a>


css:
.fa-map-marker {
	padding-left: 15px;
	color: #BCBBBB;
}

.fa-map-marker.active {
	color: #45C8DC;
}


jquery:
$(function(){
		$('.fa-map-marker').click(function() {
			$(this).toggleClass('active');
		});
});


Is This A Good Question/Topic? 0
  • +

Replies To: toggleClass()

#2 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4303
  • View blog
  • Posts: 13,677
  • Joined: 08-June 10

Re: toggleClass()

Posted 08 June 2016 - 08:52 AM

you have a link there (to the current page). when you click on that, the page is (re)loaded. and on load all state from the previous page gets discarded.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1