Break it down into what is happening when.
1. You assign a click function to #windowOpen 2. You assign a click function to all elements currently in the DOM that have a class of 'in_dom' 3. You click the button to add the new list item - item is added 4. You click the button on the newly added list item - nothing happens Nothing happens in 4 because at the time you assigned the click function to the 'in_dom' classed elements, the item added in step 3 - and clicked on in step 4 - did not exist, so there is no click handler assigned to it. scottnath wrote: > > > Hi, > > I'm trying to insert a new list item, but when I do it seems that jquery > does not recognize that the new item is in there and jquery functions > don't work on it. An example is below: > > <script type="text/javascript"> > > $(document).ready( > function () { > $("#windowOpen").click(function(){ > var z = "<li id=\"row_45\" class=\"row_full > sortableitem\"><button > class=\"in_dom\" id=\"btn_45\" value=\"click me\">NEW click > me</button></li>"; > $(z).insertBefore("#row_2"); > }); > $(".in_dom").click(function(){ > alert("that's in the dom"); > }); > }); > </script> > > > <button id="windowOpen" value="fuckyeah">show div</button> > <ul id="orderedlist"> > <li id="row_1" class="row_full sortableitem"><button > class="in_dom" > id="btn_1" value="click me">click me</button></li> > <li id="row_2" class="row_full sortableitem"><button > class="in_dom" > id="btn_2" value="click me">click me</button></li> > <li id="row_3" class="row_full sortableitem"><button > class="in_dom" > id="btn_3" value="click me">click me</button></li> > <li id="row_4" class="row_full sortableitem"><button > class="in_dom" > id="btn_4" value="click me">click me</button></li> > </ul> > > > ** When #row_45 is inserted, the .in_dom button does not work on click > > > Any help on this would be greatly appreciated. Thanks all! > > -Scott > -- View this message in context: http://www.nabble.com/insertBefore-not-inserting-into-dom--tf4539932s27240.html#a12960643 Sent from the jQuery General Discussion mailing list archive at Nabble.com.