Problem with AJAX & Delegates.
Hey!
I actually have the problem, which is discribed in the F.A.Q of JQuery - http://docs.jquery.com/Frequently_Asked_Questions#Why_do_my_events_stop_working_after_an_AJAX_request.3F
So I tried delagates. The problem now is, that the hover effect i wanted to create over a table, does only work every second time I click a link. That's rather strange.
What am I doing wrong?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>JUST A TEST</title>
<link rel="stylesheet" type="text/css" href="style.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("a").click(function(event){
$("#text").delegate("tr", "hover", function(){
$(this).toggleClass("hover");
});
$.ajax({
type: "POST",
url: "AjaxScript.php",
data: ({func: this.getAttribute("id")}),
async: false,
success: function(html){
$("#text").html(html);
}
});
event.preventDefault();
});
});
</script>
</head>
<body>
<div class="whole">
<div class="top">
DANCING KING<br/>
A demo project for the FH Salzburg.
<div class="naviontop">
<a href="" id="Taenzer">Tänzer</a>
<a href="" id="Tanzclub">Tanzsportclubs</a>
<a href="" id="Tanzpaar">Tanzpaare</a>
</div>
</div>
<div class="content">
<p id="text">testtest</p>
</div>
</div>
</body>
</html>
My Css for that:
* { font-family: Georgia, Verdana; font-size: 10pt; color: gray; }
div.top { position: relative; width: 50%; background-color: gray; color: white; margin: auto; padding: 1em 2em;}
div.content { position: relative; width: 50%; margin: auto; background-color: #DDDDDD; padding: 1em 2em;}
div.naviontop { position: relative; float:right;}
tr { border-left: solid white; }
a { text-decoration:none; color:white;}
a:hover { color: white; padding-left: 3px; border-left: thick solid white; }
tr.hover { background-color:#EEEEEE;}
It's all quite simple, but i can't understand why my planned effect works just every second time... :/
Thanks for your help in advance!