Click here to Skip to main content
15,885,767 members
Articles / jQuery

jQuery Button with Image

Rate me:
Please Sign up or sign in to vote.
5.00/5 (1 vote)
6 Jan 2012CPOL 28.4K   1   2
How to add a jQuery Button with Image to a web page in a few steps

This post illustrates how to add a jQuery Button with Image to a web page in a few steps.

The first step is to add the Button’s HTML code. The jqxButton can be created either from DIV tag or INPUT tag. To display an image in the Button, we need to create it from a DIV tag. In the HTML below, we add a DIV tag for the Button, IMG tag for the Button’s image and another DIV tag for the Button’s Text.

HTML
<div id='jqxButton'>
    <img style='float: left; margin: 4px;' src='../../images/numberinput.png' />
    <div style='float: left; margin: 4px;'>
        Button</div>
</div>

The second step is to add the dependency script files. To use the jQWidgets Button, we need to add following JavaScript files to the web page.

HTML
<script type="text/javascript" src="../../scripts/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxcore.js"></script>
<script type="text/javascript" src="../../jqwidgets/jqxbuttons.js"></script>

The third step is to add the CSS stylesheet files. In this post, we will use the ‘DarkBlue’ theme and we need to load the base and darkblue styles.

HTML
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.base.css" type="text/css" />
<link rel="stylesheet" href="../../jqwidgets/styles/jqx.darkblue.css" type="text/css" />

The final step is to create the Button by using the jqxButton constructor. We pass three parameters to the constructor – width, height and theme name.

JavaScript
$("#jqxButton").jqxButton({ width: '80px', height: '25px', theme: 'darkblue' });

jQuery Image Button

This article was originally posted at http://www.jqwidgets.com/jquery-button-with-image

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
jQWidgets
United States United States
jQWidgets specializes in the development of platform independent and cross-browser compatible presentation layer components for building modern web-based applications for PC, Touch and Mobile. Our product provides developers with the essential set of User Interface widgets needed to streamline their development and reduce project costs.
Our goal is to help our customers deliver better web-based applications that can be accessed through any device and are pleasure to use.
This is a Organisation

13 members

Comments and Discussions

 
QuestionWhere to write the initialize code Pin
Nouman Bhatti29-Aug-12 2:49
Nouman Bhatti29-Aug-12 2:49 
is it with in the script tags under head section??
AnswerRe: Where to write the initialize code Pin
Nouman Bhatti29-Aug-12 2:54
Nouman Bhatti29-Aug-12 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.