James-Jesse Drinkard
James-Jesse Drinkard

Reputation: 15713

How to setup default icons in button using jQuery

I'm using jQuery 1.8.2, jQuery ui 1.9.1, Firefox 16.0.1, in a jsp and I'm trying to get a button to display an icon. What I tried was:

$('button').button({ icons: {primary: "ui-icon-triangle-1-s" } });

and in the div:

<div id="buttonDiv" style="text-align: center;"> <button class="btn-primary"  type="button" id="confirmationButton" value="confirm">Confirmation</button> </div>

and then I tried using an id, a class, set the type to button, etc..., but for some reason it's not displaying.

I know that if I tried to make the button an input button, that wouldn't work by design and when I use

$('button').button() etc.. as a selector it's working fine.

Here are my cdn declarations:

<!-- Reference the theme's stylesheet on the Google CDN -->
    <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>

    <!-- Reference jQuery and jQuery UI from the CDN. Remember that the order of these two elements is important -->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js" type="text/javascript"></script>

What am I missing here?

Upvotes: 0

Views: 1680

Answers (1)

Brian
Brian

Reputation: 161

Are you sure you are not missing any other resources? Have you included the required CSS and images ?

Specifically jquery-ui.css : http://code.jquery.com/ui/1.9.1/themes/base/jquery-ui.css and http://code.jquery.com/ui/1.9.1/themes/base/images/ui-icons_222222_256x240.png

EDIT:

Using your script tag's, i quickly wrote this up and it works.

<!doctype html>
    <html>
    <head>
        <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/themes/ui-lightness/jquery-ui.css" rel="stylesheet" type="text/css"/>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js" type="text/javascript"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js" type="text/javascript"></script>
        <script type="text/javascript">
        $(document).ready(function(){
            $('button').button({ icons: {primary: "ui-icon-triangle-1-s" } });
        });
        </script>
        </head>
    <body>
        <div id="buttonDiv" style="text-align: center;"> <button class="btn-primary"  type="button" id="confirmationButton" value="confirm">Confirmation</button> </div>
    </body>
    </html>

Upvotes: 1

Related Questions