javascript - add and remove css class on hover -


so have code , works:

$('.col-main').on('mouseenter', '.product-wrapper', function () {   $( ).addclass( "js-hover" ); }); $('.col-main').on('mouseleave', '.product-wrapper', function () {   $( ).removeclass( "js-hover" ); }); 

but want bit more elegant. this:

listcontainer.on( {   mouseenter: function() {     $( ).addclass( "js-hover" );     console.log( "hoooover" );   },   mouseleave: function() {     $( ).removeclass( "js-hover" );   } }, productwrapper ); 

but can´t work :) appreciated

i think problem productwrapper variable. try followoing.

var listcontainer=$('.col-main') var productwrapper='.product-wrapper';  listcontainer.on( {     mouseenter: function() {         $( ).addclass( "js-hover" );         console.log( "hoooover" );     },     mouseleave: function() {         $( ).removeclass( "js-hover" );    } }, productwrapper ); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

dataset - MPAndroidchart returning no chart Data available -

post - imageshack API cURL -