try using single quotes
I need help creating a javascript that will change the source for an image using the following
Code:<img id="wrench" src="spanners.jpg" alt=".." width=".." height= ".." /> document.getElementById("wrench").src= "monkey_wrench.jpg";
The java script would run when i click a button that is tied to a specific picture and display that photo by change the source information.
However I have tried a couple things but nothing seems to work... Can someone at least point me in the right direction.
CLICK-> Online Gamer Tags ** Job - Senior Dynamics 365 Consultant ** CLICK-> Surface Pro 4 128GB || DESKTOP->IF THE TRUTH HURTS CLOSE THE THREAD
If being a nerd means I make more money than you by just walking into a room, while still having a wife and social life... then it SUCKS To Be YOU!
try using single quotes
>>Insert something witty here<<
Just a silly question.....Why would you want to change the image source?
"To err is human - and to blame it on a computer is even more so."
Alcatel One Touch PIXI 3 (4.5)
"The best software is the one that fits your needs." - A_A
Virus free since: date unknown
Anti-virus free since: August 2009
wouldn't this requires ajax... Since the page not reloading.
Owned:
>> Samsung Galaxy Note 3; LG Optimus G; Nexus 4; Samsung Galaxy Ace Duos
<< Microsoft Surface RT; Dell Venue 8; Asus Transformer
Last edited by datdread; Feb 2, 2014 at 10:30 AM.
First I'd recommend that you use jQuery or Sizzle for selecting because in production that's what you'll be using anyway. If you're using jQuery swapping the src is dead simple:
$('#link-selector').click(function(e){
e.preventDefault();
$('#wrench').attr('src', 'monkey_wrench.jpg');
});
"Fortune Favors the Bold" -Virgil
Can you assign the src= to a variable and then assign the variable to another image using the onClick method?
.
PC - Ubuntu 15.04 64bit Desktop
HP Pav G60-236US 3GB RAM Laptop, Ubuntu 15.04 64bit and Win7 Home
"So Daddy, how come you telling me stealing not right when YOU copying DVDs? How come? How Come?"
Changes to posting in Classifieds
Last edited by datdread; Feb 2, 2014 at 06:21 PM.
Owned:
>> Samsung Galaxy Note 3; LG Optimus G; Nexus 4; Samsung Galaxy Ace Duos
<< Microsoft Surface RT; Dell Venue 8; Asus Transformer