JavaScript Image Size

+1 Robert Summers · October 6, 2014
Hello I have done written out some javacript and tested it from this tutorial:

Does anyone know how I can change the image size?

Thank you for your help
<!DOCTYPE html>
<title>JavaScript Example</title>
<script type="text/javascript">

var image_tracker = 'f';
function change(){
var image = document.getElementById('social_logo');
image.src = 'twitter.png';
image_tracker = 't';
image.src = 'facebook.png';
image_tracker = 'f';

<img src="facebook.png" alt="facebook" id="social_logo" onclick="change();"/>

Post a Reply


Oldest  Newest  Rating
+1 Phillip Drake · October 6, 2014
Hello, you can change the image size with javascript by adding the following code inside your if statement: = "100px"; = "100px";

I hope this answers your question.
+1 Robert Summers · October 6, 2014
Thank you this has been helpful. :)

0 Andrew Lopez-Dillard · October 9, 2014
I know this is very late but, you can change the size in many ways HTML style attribute, Javascript (.style.width = "#%"), and my favorite CSS:
<img style="width: 100px; height: 100px;></img>

width: 100px;
height: 100px;

/*JavaScript*/ = 100px; = 100px;

I'd recommend working with percentage instead of pixels.

display: flex; /*This line isn't needed*/
width: 16%;
height: 16%;

0 Robert Summers · October 9, 2014
Hey, no worries. Thank you for your help though :)
  • 1



A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.