You will need to assign the click to the newly created DOM elements.
The elements MUST be attached to DOM before you can assign an event
otherwise, the event will not be bound. 

I think this achieves what you want in jQuery plugin format ;)

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd";>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Recursive Event Assignment</title>
<style type="text/css">
.lin {
  cursor:pointer;
}

</style>
<script type="text/javascript" src="/jquery/jquery.js"></script>
<script type="text/javascript">
$.fn.createLink = function() {
  
  this.click(function() {
     var text = "Child of "+$(this).text();
     var newLink = $("<span class='lin'>"+text+"</span><br/>");
     $("#sublevels").append(newLink);
     newLink.createLink(); // can only bind events AFTER an element is
attached to the DOM
   }); 
};

$().ready(function () {
   $(".lin").createLink();
  
});

</script>

</head>
<body>
  <h1>Main Links</h1>
  <ul>
    <li class="lin">Link 1</li>
    <li class="lin">Link 2</li>
    <li class="lin">Link 3</li>
  </ul>
  
  <h1>Sublevels</h1>
  <div id="sublevels">
  </div>

</body>
</html>


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On
> Behalf Of phplord
> Sent: Thursday, March 08, 2007 12:36 PM
> To: discuss@jquery.com
> Subject: [jQuery] checking created items again via DOM
> 
> 
> Hi;
> 
> I got an interesting problem.
> 
> I have a code like this:
> 
> $('.lin').click(function(){
>          $("#sublevels").append("<span
class='lin'>"+split[1]+"</span><br
> />");
> }
> 
> As you see,I have been adding span tags with class lin when another
span
> tag
> with class lin was clicked.
> 
> Problem is created span tags with class link must run this code also
when
> they are clicked because they have the same class name (lin)
> 
> But they donot work
> 
> What's the problem?
> --
> View this message in context: http://www.nabble.com/checking-created-
> items-again-via-DOM-tf3369155.html#a9374259
> Sent from the JQuery mailing list archive at Nabble.com.
> 
> 
> _______________________________________________
> jQuery mailing list
> discuss@jquery.com
> http://jquery.com/discuss/

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/

Reply via email to