I am trying to echo out some JavaScript, but I can’t get the formatting right I start off by putting the javascript I want to out into a string
$javascript = 'onmouseover="this.style.backgroundColor='blue'" onmouseout="this.style.backgroundColor='white'"';
and then echo it out like this
$hint="<span $javascript>".$artistname->item(0)->childNodes->item(0)->nodeValue."</span>";
any help would be much appreciated
Using the event attributes is considered bad practise. JavaScript should be unobtrusive. Also, I do not see why you would have to store the attributes in a PHP variable instead of simply adding them to the span tag directly. And last but not least, why dont you just use the CSS
:hoverselector to change the background color when the mouse is over the span? That would be a clean approach.