views:

73

answers:

1

Hi,

I am looping over the first set of li a tags in my UL and getting the height so that I can deliver a different background image if the a > span > span text wraps across two or three lines.

I need to be able to store these specific buttons in an array, so that when I mouse over them, the current span with double line text receives a different background image.

Here's what I have and I am not sure where to go from here. I'd appreciate some help.

   var doubleLineButtons = new Array();

$("div.subSectNav .RadPanelBar ul.rpRootGroup > li.rpItem > a").each(function (i) {

    if ($(this).height() > 35) {

        doubleLineButtons.push($(this))

        // here I need to access any possible menu items if the lines have wrapped and deliver a different background image
        doubleLineButtons[i].hover(function(){
            // change the background image of this button
            (this).css('background', 'url("/App_Themes/2010a/images/background_nav_sub_left_double.png") no-repeat scroll 0 0 transparent');
        },
        function(){
            // remove the background image from this button
        });

    }

});

Thanks a bunch!

+3  A: 

I don't see why you need to store them in an array if all you are wanting to do is change the background image. The following working example at http://jsfiddle.net/h6GTW/ should get you going along the right lines.

$('li').each(function() {
    if ($(this).height() > 35) {
        $(this).hover(function() {
            $(this).css('background', 'red');
        }, function() {
            $(this).css('background', 'white');
        });
    }
});?
Blair McMillan
To remove a background, use `$(this).css('background', 'none');`
Ryan Kinal
Wow...love jsFiddle Blair. Not seen it before! Thanks for your example above. I will give this a try now!
Sixfoot Studio
Worked like the bomb! Thanks guys!
Sixfoot Studio