hi, i am not sharing code. the problem is in this code please take a look. (problem: I want to open facebox every time when post even come from ajax facebox is not working properly. I want to ask how to use jQuery delegation event with this event? )
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="facebox/facebox.css" type="text/css" />
</head>
<body>
<ul id="items">
<li> <a href='#'> Clone Object </a> </li>
<li> <a href='#test' rel='facebox'> Click to open facebox </a> </li>
</ul>
<div id="test" style="display:none;">this is my test div</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script type="text/javascript" src="facebox/facebox.js"></script>
<script type="text/javascript">
jQuery('a[rel*=facebox]').facebox();
$("#items li").delegate('a', 'click', function(){
$(this).parent().append('<li><a href="#test" rel="facebox"> New Element ( problem: it should open facebox) </a></li>');
return false;
});
</script>
</bdoy>
</html>
A few things, first change to using
.live(), by switching this:For this:
Or the
.delegate()version:Then your
.parent()call is appending an<li>to an<li>, instead you should replace:With
.cloest()so it goes up to the<ul>and appends it as a child there, like this:You can test out the updated version with the above changes (without images) here.