html - src image changer after click with JavaScript -
i have image in html page:
<img src="/images/deactivate.png" onclick="act_deact(this);"/>
and in javascript code have this:
function act_deact(image) { image.src = (image.src=="/images/activate.png" ) ? "/images/deactivate.png" : "/images/activate.png"; }
and when click on image deactivated activate in second click doesn't desactivate !
is there probleme code ?
from js amateur :)
this because when set to(or changes to) /images/activate.png
on first click, src
attribute no longer /images/activate.png
gets prefixed server-address.
you can check here: http://jsfiddle.net/hgcqq/
or on own server, use console.log
or alert
if prefer.