I am trying use this function that changes the class and onclick of another element.
partner = this.id + 'Content';
document.getElementById(partner).className = 'newswrapper';
document.getElementById(partner).onclick = function(){ clickNews(this); } ;
the id of the element with the onclick looks like this.
echo'<div id="newsSlide'.$counter.'" class="newsimage"
onclick="clickNews(this)"
style='."'".'background-image:url("../img/'.$row['image'].'")'".'>';
and the element that is supposed to have its class changed looks like this
echo'<div id="newsSlide'.$counter.'Content" class="newswrapper">';
getting the error Uncaught TypeError: Cannot set property 'className' of null
echo'<script>';
echo"function clickNews(id)
{
var y = document.getElementsByClassName('newswrapper');
var x = document.getElementsByClassName('newswrapper2');
var length = y.length,
element = null;
for (var i = 0; i < length; i++) {
element = y[i];
element.className = 'newswrapper2';
}
var length = x.length,
element = null;
for (var i = 0; i < length; i++) {
element = x[i];
element.className = 'newswrapper2';
}
partner = this.id + 'Content';
document.getElementById(partner).className = 'newswrapper';
document.getElementById(partner).onclick = function(){ clickNews(this); } ;
}";
echo'</script>';
the html can be found here : http://pastebin.com/6xBNBQwZ or you can use the HTML inspector on the actual page here here : http://www.uk-sf.com/indextest.php