I'm trying to create a website where HTML-code gets loaded into a div when document is done loading. Though, the hover function doesn't work with AJAX-load. Please help.
$(document).ready(function() {
$('#sidebar').load('sidebar-main.php');
$("#sidebar .section").hover(function() {
$('#sidebar .section .left-mark').show();
},function(){
$('#sidebar .section .left-mark').hide();
});
});
The "sidebar-main.php" file:
<div class='section' onclick='header()'><div class='left-mark'></div></div>
The sidebar in the main PHP-file:
<div id='sidebar'></div>
onhandler for ajax like$("#sidebar .section").on('hover',function(){ ...});load()has a callback function when the load has completed. This means, I think, it works asynchronous. So I advice to use the callback function. See: api.jquery.com/load