TacMaf
April 20, 2011, 10:58pm
1
Hi,
I have a slight problem (mostly my brain has stopped working!). All I’m trying to do is have an image which the border is added on click, and removes the border onclick again.
<img src=\\"".$targetPath.$file."\\" ".imageResize($mysock[0], $mysock[1], 150)." border=\\"0\\" onClick=\\"this.style.border='3px solid #e25e00';\\">
That works fine, but how can I change it back on another click?
Thanks.
Move the change off to a CSS style, so that you only need to run a function to toggle that class name.
.active {
border: 3px solid #e25e00;
}
"... onClick=\\"toggleBorder(this);\\">
function toggleBorder(link) {
if (link.className === 'active') {
link.className = '';
} else {
link.className = 'active';
}
}
TacMaf
April 21, 2011, 12:48am
3
That worked great. Thanks, much appreciated.