By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,628 Members | 1,747 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,628 IT Pros & Developers. It's quick & easy.

Table-tag

P: n/a
Hello,

I have a little question which should be easy, nevertheless i can't
solve the problem.

I want to change the background of a <td>-tag when you click on a link
in the html-page.

This is what I've got but it doesn't work:

<script type="text/javascript">
function change()
{
var x=document.getElementById('table').rows
var y=x[0].cells
y[0].background="../images/knoplinks.gif"
}

<script>

<table id="tabel">
<tr>
<td background="../images/knop2.gif">
<a href="#" onclick="change()">Gegevens</a>
</td>
</tr>
</table>

Jul 23 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Nattydreadlock" <Be********@hotmail.com> skrev i meddelandet
news:11**********************@z14g2000cwz.googlegr oups.com...
Hello,

I have a little question which should be easy, nevertheless i can't
solve the problem.

I want to change the background of a <td>-tag when you click on a link
in the html-page.

This is what I've got but it doesn't work:

<script type="text/javascript">
function change()
{
var x=document.getElementById('table').rows
Add ";"
var y=x[0].cells
Add ";"
y[0].background="../images/knoplinks.gif"
Add ";"
And you probably want "y[0].style.background =
url(../images/knoplinks.gif)".
(or "y[0].style.backgroundImage....".)
}

<script>
Should be: "</script>".
<table id="tabel">
But you wrote "getElementById('table')".
<tr>
<td background="../images/knop2.gif">
<td> doesn't have a background attribute (at least not in HTML 4.0).
Perhaps you want "<td style="background-image:url(../images/knop2.gif)">".
<a href="#" onclick="change()">Gegevens</a>
</td>
</tr>
</table>


--
Joakim Braun
Jul 23 '05 #2

P: n/a
Hello,

I checked the syntax problems but still it doesn't work. I tried
different things but I couldn't find the solution yet.
Here is what I think is closest to the solution

<script type="text/javascript">
function change()
{
var x=document.getElementById('tabel').rows;
var y=x[0].cells;
y[0].style = "background-image:url(../images/knop2klik.gif)";
}
</script>
<table id="tabel">
<tr>
<td style="background-image:url(../images/knop2.gif)">
<a href="#" class="navlinks"
onclick="change()">Gegevens</a>
</td>
</tr>
</table>

Jul 23 '05 #3

P: n/a
Ivo
"Nattydreadlock" wrote

y[0].style = "background-image:url(../images/knop2klik.gif)";


Make that:
y[0].style.backgroundImage = "url(../images/knop2klik.gif)";

with an uppercase i.

hth
--
Ivo
Jul 23 '05 #4

P: n/a
On 25/03/2005 12:27, Nattydreadlock wrote:

[snip]
I want to change the background of a <td>-tag when you click on a link
in the html-page.
Make sure that if you set a background image, you also set both a
background and foreground colour. You shouldn't rely on defaults in
case a user doesn't have those same defaults.

[snip]
y[0].background="../images/knoplinks.gif"
Use the backgroundImage property of the style object, and the url(...)
functional notation, as shown in Ivo's post.

[snip]
<a href="#" onclick="change()">Gegevens</a>


You'll probably want to cancel the click event. Return false from the
listener:

onclick="change(); return false;"

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.