Skip to content

Instantly share code, notes, and snippets.

@madzak
Created February 18, 2014 16:53
Show Gist options
  • Save madzak/9074840 to your computer and use it in GitHub Desktop.
Save madzak/9074840 to your computer and use it in GitHub Desktop.
Jquery Conversion
$(function(){
$('#variations-test .swatches a').hover(function(){
$('#variations-test .variation-color').html( $(this).attr('data-color') );
}, function() {
$('#variations-test .variation-color').html( $('#variations-test .swatches a.active').attr('data-color') );
});
});
var variations = document.getElementById('variations-test'),
swatchLinks = variations.querySelectorAll('.swatches a'),
variationColor = variations.querySelector('.variation-color');
for(var i=0; i< swatchLinks.length; i++) {
swatchLinks[i].addEventListener('mouseenter', function(evt) {
variationColor.innerHTML = this.getAttribute('data-color');
});
swatchLinks[i].addEventListener('mouseleave', function(evt) {
var active = variations.querySelector('.swatches a.active');
variationColor.innerHTML = active.getAttribute('data-color');
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment