S
SM
Hello, i need to add a classname to an element <a> using JavaScript.
I've tried a couple of thing with no success.
This is an small piece of my code:
....
<li><a href="<?php echo $cd_img; ?>" onClick="show_picture(this);
return false;">image 1</a></li>
<li><a href="<?php echo $cd_img; ?>" onClick="show_picture(this);
return false;">image 2</a></li>
....
<img id="cover" src="<?php echo $cd_cover; ?>" alt="" /></div>
function show_picture(picture) {
var source = picture.getAttribute("href");
var cover = document.getElementById("cover");
cover.setAttribute("src", source);
//??????doesnt work
var el_a = document.getElementById("a");
el_a.className = "here";
}
Any ideas?
Thanks
Marco
I've tried a couple of thing with no success.
This is an small piece of my code:
....
<li><a href="<?php echo $cd_img; ?>" onClick="show_picture(this);
return false;">image 1</a></li>
<li><a href="<?php echo $cd_img; ?>" onClick="show_picture(this);
return false;">image 2</a></li>
....
<img id="cover" src="<?php echo $cd_cover; ?>" alt="" /></div>
function show_picture(picture) {
var source = picture.getAttribute("href");
var cover = document.getElementById("cover");
cover.setAttribute("src", source);
//??????doesnt work
var el_a = document.getElementById("a");
el_a.className = "here";
}
Any ideas?
Thanks
Marco