Here I want to style my table with css. But when I try to add this events inside echo, it says,
Parse error: syntax error, unexpected 'this' (T_STRING), expecting ',' or ';' in E:\xampp\htdocs\Ceylon Aviation\Flights.php on line 146
As I'm a beginner to PHP, I can't figure out the exact error. Any helpful suggestions to edit my code? Thank You!
My Code:
echo "<tr onmouseover = /"this.style.backgroundColor = /'#ffff66' ; " onmouseout = /"this.style.backgroundColor = /'#d4e3e5';">";
This works too:
echo "<tr onmouseover='this.style.backgroundColor=#ffff66' onmouseout='this.style.backgroundColor=#d4e3e5'>";
Change it to call javascript functions: in changeColor function
function changeColor(){ this.style.backgroundColor = '#ffff66'; }
Point one, onmouseover
and onmouseout
are JavaScript events.
Point two, you can use the :hover
from css.
Point three, you only need to echo the html
var div = document.getElementById("js");
//set width and height
div.style.width = "100px";
div.style.height = "100px";
//set the start color
div.style.backgroundColor = "#F0F";
function OnMouseOver(o) {
o.style.backgroundColor = "#F00";
}
function OnMouseOut(o) {
o.style.backgroundColor = "#F0F";
}
#css {
width: 100px;
height: 100px;
background-color: #0FF;
}
#css:hover {
background-color: #00F;
}
<div id="js" onmouseover="OnMouseOver(this)" onmouseout="OnMouseOut(this)">
</div>
<div id="css">
</div>
I added a snippet to show both css
and JavaScript
ways
</div>