Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
100
rated 0 times [  105] [ 5]  / answers: 1 / hits: 19918  / 12 Years ago, fri, april 13, 2012, 12:00:00

I have created a button in javascript and I would like to use an image for the button instead of text, but I have not yet found a way to do this. So far the sources I have referenced are not working for me for some reason. What I have so far is as follows



Javascript



var sb=doc.createElement('input');              
sb.type='button';
//sb.value='Find';
sb.src = url(/Resources/Icons/appbar.next.rest.png);
sb.style.height='100%';
//sb.style.width='20%';


where my image is locoated in the directory /Resources/Icons/appbar.next.rest.png in my project. Can someone point me in the right direction as to how to properly use an image for a button? I am new to javascript so any links, code, or directions would be greatly appreciated!


More From » jquery

 Answers
9

for adding image to button you can change type of input from button to image:



var body = document.getElementsByTagName(body)[0];
var s = document.createElement(input);
s.src = http://www.gravatar.com/avatar/a4d1ef03af32c9db6ee014c3eb11bdf6?s=32&d=identicon&r=PG;
s.type = image;
body.appendChild(s);


you can modify it.



http://jsfiddle.net/6HdnU/


[#86266] Thursday, April 12, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kennedysaraiw

Total Points: 552
Total Questions: 99
Total Answers: 109

Location: South Sudan
Member since Sun, Jul 11, 2021
3 Years ago
;