whiteElephant
whiteElephant

Reputation: 263

Retain hover over effect on link

I have 5 links which act as a bit of a navigation bar, they are a light blue to start with, when one of them is hovered over or clicked I would like them to change color and retain that color until another link is selected.

I have had a good search for a solution and there are many but they all seem to be for a particular case and I just can't seem to adapt them.

Any help would be greatly appreciated.

heres my html here, I have a css file making it look pretty as well.

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org /TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">

<head>


  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>

  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

  <script>

  $(function() {

    $( "#tabs" ).tabs({

      event: "mouseover"

    });

  });


  </script>

<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Menu bar</title>
<style type="text/css" />
</style>

  <link href="navPanelStyle.css" rel="stylesheet" type="text/css" />

</head>

<body>

 <div id="tabs">

  <div id="topBar">
  <ul>

    <li><a href="#Booking">BOOKINGS</a></li>

    <li><a href="#Rooms">ROOMS</a></li>

    <li><a href="#news">NEWS</a></li>

    <li><a href="#Specials">SPECIALS</a></li>

    <li><a href="#About_us">ABOUT US</a></li>

  </ul>
  </div>
<div id="content_Wrapper">
  <div id="Booking">

<p>Bookings</p>
  </div>

  <div id="Rooms">

<p>Rooms</p>
  </div>

  <div id="news">


<p>news</p>
  </div>


  <div id="Specials">

<p>Specials</p>

  </div>



  <div id="About_us">

<p>About us</p>

  </div>


</div>
</div>


</body>

</html>

Upvotes: 0

Views: 209

Answers (2)

PSL
PSL

Reputation: 123739

If you can use Jquery to do this you can try this way, to retain a style for selected tab.

Demo

JS

$("#tabs").tabs({

    event: "mouseover",
    select: function (event, ui) {

        $('.active').removeClass('active');
        $(ui.tab).addClass('active'); // ui.tab in the select event will be currently selected tab.

        // Do stuff here
    }

});

Css

#tabs .active {
    color:Blue;
}

if you want to apply over the entire tabe you can apply your styles to li tab element as follows:-

$(ui.tab).closest('li').addClass('active');

Demo2

Upvotes: 3

Powerslave
Powerslave

Reputation: 1428

You need to set up a piece of hover-over listener JavaScript code that removes active class from the element that was last activated and add it to the one that's hovered over.

Like the following:

$(".menuitem").hover(
    function() {
        $(this).addClass("active_menuitem");
    },
    function() {
        $(this).removeClass("active_menuitem");
    }
)

A menuitem can be anything that the CSS related to the active menu item class can be applied to

Upvotes: 1

Related Questions