So what I have is a php script that queries a database, and creates a number of elements which display both a red team abbreviation, and a blue team abbreviation (much like the schedule strip on the top of nfl.com). I am trying to acoomplish the following:
On mouse hover of a game element (class=game), swap out the div layer with one that contains the date and time of the match.
What I am having trouble with is somehow relating the two items together within jQuery. I can get jQuery to know what item it needs to hide, but not what item it needs to replace it with.
$db = get_database_connection();
$today = date("Y-m-d");
$sql='
SELECT game_date as date,
game_time as time,
stred.team_name AS redteam,
stblue.team_name AS blueteam,
stred.team_abbreviation as redteamabbrev,
stblue.team_abbreviation as blueteamabbrev
FROM stats_tblGames
INNER JOIN stats_tblTeams AS stred ON stats_tblGames.fk_id_team_red = stred.id_team
INNER JOIN stats_tblTeams AS stblue ON stats_tblGames.fk_id_team_blue = stblue.id_team
ORDER BY date ASC
LIMIT 5
';
echo '<div class="switch">';
foreach ($db->query($sql) as $row) {
$date = $row['date'];
if($today > $date) {
$time = date('g:i A T',($row['time']));
$redteam = $row['redteamabbrev'];
$blueteam = $row['blueteamabbrev'];
$control = $date . $redteam;
$control2 = $redteam . $date;
# Convert date
$format = date_format(new DateTime($date), 'D, M j');
echo "<div id='$control' class='game'>";
echo '<strong class="red-team">' . $redteam . '</strong><br>';
echo '<strong class="blue-team">' . $blueteam . '</strong>';
echo '</div>';
echo "<div id='$control2' class='game hide'>";
echo '<strong>' . $format . '</strong><br>';
echo '<strong>' . $time . '</strong>';
echo '</div>';
# Script to hide/show games on hover
}
}
echo '</div>';
echo '<p class="clearfix"></p>';
?>
<script type="text/javascript">
jQuery('.game').mouseover(function() {
jQuery(this.id).hide();
jQuery(this.id).closest(SHOWID).show();
});
</script>
jQuery(this.id)with$(this)document.ready().gameelement clearly exists already. All that putting that code into a document.ready handler would do is make the mouseover start working a little later than it should.