Question

I am using http://jqueryui.com/selectable/#default exmaple

Is it possible to add hover event once i hover a selectable item?

<!doctype html>

<html lang="en">
<head>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.9.0/themes/base/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script src="http://code.jquery.com/ui/1.9.0/jquery-ui.js"></script>
    <link rel="stylesheet" href="/resources/demos/style.css" />

    <style>
    #feedback { font-size: 1.4em; }
    #selectable .ui-selecting { background: #FECA40; }
    #selectable .ui-selected { background: #F39814; color: white; }
    #selectable { list-style-type: none; margin: 0; padding: 0; width: 60%; }
    #selectable li { margin: 3px; padding: 0.4em; font-size: 1.4em; height: 18px; }
    </style>
    <script>
    $(function() {
        $( "#selectable" ).selectable();
    });
    </script>
</head>
<body>

<ol id="selectable">
    <li class="ui-widget-content">Item 1</li>
    <li class="ui-widget-content">Item 2</li>
    <li class="ui-widget-content">Item 3</li>
    <li class="ui-widget-content">Item 4</li>
    <li class="ui-widget-content">Item 5</li>
    <li class="ui-widget-content">Item 6</li>
    <li class="ui-widget-content">Item 7</li>
</ol>


</body>
</html>
Was it helpful?

Solution

Since all your selectable items have a class .ui-widget-content, this can be achieved easily using the :hover pseudoselector:

.ui-widget-content:hover {
    background-color: orange;
}

If you want to handle the hover event in JavaScript, use something like:

$(".ui-widget-content").hover(function() {
    //what to do on hover
}, function() {
    //what to do when hover ends
});

OTHER TIPS

The Selectable plugin is automatically adding the class "ui-selectee" to all the Selectable objects and this why you can use:

.ui-selectee:hover {
    background-color: orange;
}
$('#selectable li').hover(function(){
//CODE HERE
});

All the li in selectable gets the hover function.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top