O'Reilly logo

jQuery UI Cookbook by Adam Boduch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Sorting buttons within a group

We can use the sortable() interaction widget to provide the user which some flexibility. Why not let the user move buttons around? Especially given the small amount of code it takes.

Getting ready

We'll use a list to organize our buttons, as follows:

<ul>
    <li><a href="#">Button 1</a></li>
    <li><a href="#">Button 2</a></li>
    <li><a href="#">Button 3</a></li>
</ul>

We'll use the following CSS to fix the list layout to better display button widgets.

ul {
    list-style-type: none;
    padding: 0;
}

li {
    margin: 4px;
}

How to do it...

The JavaScript code to make this happen is actually quite miniscule—we create the buttons, then we apply the sortable interaction widget.

$(function() { $( "a" ).button(); $( "ul" ).sortable({ opacity: 0.6 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required