Skip to content

Instantly share code, notes, and snippets.

@nastysloper
Last active December 18, 2015 07:09
Show Gist options
  • Save nastysloper/5744716 to your computer and use it in GitHub Desktop.
Save nastysloper/5744716 to your computer and use it in GitHub Desktop.
successively refactored jQuery code...
.tour{
background-color: green;
border-radius: 10px;
}
h2{
margin-top: 5px;
margin-left: 15px;
}
.details{
margin-left: 15px;
}
.highlight{
background-color: yellow;
}
.on-sale{
}
.featured{
}
$(document).ready(function(){
$("#filters").on("click", ".on-sale", function(){
$(".tour").filter(".on-sale").addClass("highlight");
$(".tour").filter(".featured").removeClass("highlight");
});
$("#filters").on("click", ".featured", function(){
$(".tour").filter(".featured").addClass("highlight");
$(".tour").filter(".on-sale").removeClass("highlight");
});
$("#filters").on("click", ".reset", function(){
$(".tour").filter(".featured").removeClass("highlight");
$(".tour").filter(".on-sale").removeClass("highlight");
});
});
<div id="tours">
<h1>Guided Tours</h1>
<ul>
<li class="usa tour on-sale" data-discount="299">
<h2>New York, New York</h2>
<span class="details">$1,899 for 7 nights</span>
<button class="book">Book Now</button>
</li>
<li class="europe tour on-sale" data-discount="176">
<h2>Paris, France</h2>
<span class="details">$2,299 for 7 nights</span>
<button class="book">Book Now</button>
</li>
<li class="asia tour featured" data-discount="349">
<h2>Tokyo, Japan</h2>
<span class="details">$3,799 for 7 nights</span>
<button class="book">Book Now</button>
</li>
</ul>
<ul id="filters">
<li><button class="on-sale">On Sale</button></li>
<li><button class="featured">Featured</button></li>
<li><button class="reset">Reset</button></li>
</ul>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment