ASA2k ASA2k - 9 months ago 27
HTML Question

How to reference an image within quotation marks in a script

I am trying to reference an image instead of using text within the script tag in a html page. I am attempting to use an image for a button instead of text. When the button is pressed it changes to the text 'Paused' as shown below.

pauseButton.innerHTML = "Paused";

When it is pressed again it displays the words 'Pause'.

pauseButton.innerHTML = "Pause";

Instead I would like it to display an image I created. This code shows a section where I tried to reference the image.

pauseButton.innerHTML = "url(Images/pausebackground.png)";

Instead of displaying the image it displays 'url(Images/pausebackground.png)' in the form of text.

How can I reference the image within the quotation marks?


You need to put HTML code into innerHTML (as the name suggests). Use an <img> tag:

pauseButton.innerHTML = '<img src="Images/pausebackground.png">';