0

I have following code, and what I am doing here is adding an inline style for background-color, and its working fine as well, but what my requirement is, when I mouseover on the div containerLink it should remove the inline style which I have added using the following and when mouseout, it should add that style attribute back with the value it has previously.

Can somebody suggest how to add the hover functionality?

$(window).on("load resize scroll",function(){
    $(".containerLink").each{(function(index, eles){
        var alphaVal = $(elem).attr('backgroundOpacity');
        if(alphaVal && alphaVal != '100')
        $(elem).css('background-color','');
        $(elem).css('background-color', funtion(index, value){
            if (value === 'rgba(0,0,0,0)'){
                return value;
            }
            if(value.match(/\d+, \d+, \d+/g) != null){
                var RGBValue = value.match(/\d+, \d+, \d+/g)[1];
                return "rgba(" + RGBValue + "," + alphaVal + ")";
            }
        });
    }
    )}
});
Sanjeev Kumar
  • 3,113
  • 5
  • 36
  • 77

2 Answers2

1

Try this :

$(".containerLink" ).each(function(){
    $(this).mouseout(function() {
        $(this).css("background-color", "#000"); 
        // OR
        $(this).attr("style","");
        // OR WHAT YOU WANT
    })
    .mouseover(function() {
        $(this).css("background-color", "#fff"); // mouse in code gose here....
    });
});
aidinMC
  • 1,415
  • 3
  • 18
  • 35
1

Here's a working example with information from:

JQuery .hover() Event

$( "#target_container" ).hover(

// Hover IN
function() {
$( this ).text("hover IN");
$( this ).css('background-color', 'lightblue');

// Hover OUT
}, function() {
$( this ).text("hover OUT");
$( this ).css('background-color', 'yellow');

}
);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="target_container" style="width:100px; height: 100px; background-color: yellow;">Ready to hover?</div>
suchislife
  • 4,251
  • 10
  • 47
  • 78