Hi site point people,
I have been playing with javascript and I have one issue I can’t workout. below in my code on a click the td will change
its background image and text color. The issue I have I can’t get the color to work but the image is find. Any help would be
great thanks
<td>
<a href="javascript:cont(specialId)" class="position-one"><span>water</span></a>
</td>
function cont(specialId){
document.getElementById(specialId).style.backgroundImage = "url(select-buttons/selected.png)";
document.getElementById(specialId).style.color = "orange";
}
system
November 6, 2011, 11:28pm
2
A few points:
<a [COLOR=#ff0000]href="javascript:cont(specialId)" [/COLOR]class="position-one"><span>water</span></a
is bad. href is meant to be used to navigate to another page, not run javascript.
A better way is
<a href="" onclick="cont('specialId'); return false;" class="position-one"><span>water</span></a>
where have you defined specialId in javascript:cont(specialId) ?
You can do it this way:
<a href="#" id="specialId" class="position-one"><span>water</span></a>
var spcID = document.getElementById('specialId');
spcID.onclick = function(e) {
e.preventDefault();
this.style.backgroundImage = "url(select-buttons/selected.png)";
this.style.color = "orange";
};
thanks I have made the changes I have the special id in the the td it is dynamically written by the php.
<td id=“specialId”> // sorry left that bit out
system
November 7, 2011, 12:07am
5
ok :), then you would also need to wrap the argument in your call to cont in quotes.