How do you customize a JQuery Button?

Take a look at this tutorial: http://www.w3schools.com/jquery/tryit.asp?filename=tryjquery_event_trigger

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.

So...

How would you replace the standard graphic you get when you use "<button>," with a customized image?
brucegustPHP DeveloperAsked:
Who is Participating?
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
0
Julian HansenCommented:
You would need some marginal styling as well
<style type="text/css">
button {
  background: none;
  border: 0;
}
</style>

Open in new window

0
brucegustPHP 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>
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

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

0
brucegustPHP DeveloperAuthor Commented:
What happens when you have more than one <button>?
0
Julian HansenCommented:
You give the button an id or a class and then target that class or id
Like this
<script>
$(function() {
  // TARGET MULTIPLE BUTTONS BY CLASS
  $('.we-are-the-many').click(function(e) {
     e.preventDefault();
     $(this).html('Gotcha');
  });
  // TARGET SINGLE BUTTON BY ID
  $('#the-one-and-only').click(function(e) {
     e.preventDefault();
     $(this).html('The one and only');
  });
});
</script>

Open in new window

Working sample here
0

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
brucegustPHP DeveloperAuthor Commented:
That'll do it!

Thanks!
0
Julian HansenCommented:
You are welcome.
0
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
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.