How do you customize a JQuery Button?

Take a look at this tutorial:

I want to customize that <button> with an image that I've created. I've seen some tutorials, but none of them include the <button> syntax which makes me want to pause and ensure there isn't a more direct approach.


How would you replace the standard graphic you get when you use "<button>," with a customized image?
Bruce GustPHP DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Julian HansenCommented:
Just put the image in the button like this

<button><img src="images/foreground1.png" /></button>

Open in new window

Sample code here
Julian HansenCommented:
You would need some marginal styling as well
<style type="text/css">
button {
  background: none;
  border: 0;

Open in new window

Bruce GustPHP DeveloperAuthor Commented:
Perfect, Julian!

See? This is why you get paid the large, executive-level dollars?

How do you trigger the JQuery event though?

Here's what I've got, but they don't trigger the function:

<button onchange="showAll();"><img src="images/all_on.png"></button><button onchange="showNone();"><img src="images/all_off.png"></button>
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

Julian HansenCommented:
Just add an event handler for the .click() event. You can bind to the element (button) or an id (if you give your button one) or a class (if you add one).
$('button').click(function(e) {
  // e.preventDefault() /* add this if you want to disable default behaviour */
  // code here for when the button is clicked.

Open in new window

Bruce GustPHP DeveloperAuthor Commented:
What happens when you have more than one <button>?
Julian HansenCommented:
You give the button an id or a class and then target that class or id
Like this
$(function() {
  $('.we-are-the-many').click(function(e) {
  $('#the-one-and-only').click(function(e) {
     $(this).html('The one and only');

Open in new window

Working sample here

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Bruce GustPHP DeveloperAuthor Commented:
That'll do it!

Julian HansenCommented:
You are welcome.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.