Skip to content

Instantly share code, notes, and snippets.

@artygrand
Created September 20, 2016 13:40
Show Gist options
  • Save artygrand/c86c51ca612cc0095d122c05a6cd9850 to your computer and use it in GitHub Desktop.
Save artygrand/c86c51ca612cc0095d122c05a6cd9850 to your computer and use it in GitHub Desktop.
Simple stars vote script for input
$(document).ready(function(){
$('.stars').each(function(){
var input = $(this), stars = $('<div class="stars-visible"><span></span><span></span><span></span><span></span><span></span></div>')
stars.find('span').click(function(){
$(this).addClass('active').siblings().removeClass('active')
input.val(5-$(this).index())
})
input.hide().before(stars)
})
})
.stars-visible {
unicode-bidi: bidi-override;
direction: rtl;
width: 130px;
}
.stars-visible span {
display: inline-block;
width: 26px;
height: 26px;
background: url(img/star-off.png);
cursor: pointer;
}
.stars-visible span:hover,
.stars-visible span.active,
.stars-visible span:hover ~ span,
.stars-visible span.active ~ span {
background: url(img/star-on.png);
}
<input type="number" name="stars" class="stars form-control">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment