SpencerQ
SpencerQ

Reputation: 91

How do you maintain element width on hover?

I want to maintain the width of an element on hover. Basically, I have put my width properties in array and want to access them when I hover it's element. Here is my code:

var tabs = $('.tab-block li').map(function(){
    return $(this).css('width');
}).toArray();
$('.tab-block li').hover(function(){
    $(this).css({'width': tabs[GET_HOVERED_ELEMENT_WIDTH]});
},function(){
    $(this).removeAttr('style');
});

Upvotes: 0

Views: 73

Answers (1)

Esailija
Esailija

Reputation: 140236

Have no idea what you are doing here but you can do something like this:

$('.tab-block li').hover(function(){
    $(this).css({'width': tabs[$(this).index()]});
},function(){
    $(this).removeAttr('style');
});

Upvotes: 1

Related Questions