There is a ticket for this already. -- Ariel Flesler http://flesler.blogspot.com
On Sep 5, 11:47 am, "John Resig" <[EMAIL PROTECTED]> wrote: > Hmm - doing .before(HTML).remove() won't be enough (since that only > helps with the #id case, not any others). Could you file a bug on > this?http://dev.jquery.com/ > > --John > > On Fri, Sep 5, 2008 at 6:52 AM, machac <[EMAIL PROTECTED]> wrote: > > > Hallo, > > > in jQuery 1.2.6 is replaceWith(HTML) method is defined as > > after(HTML).remove() > > > It's correct but if in inserted HTML is JS code witch refer some > > element ID from inserted HTML then JS may be evaluated on element with > > same ID in removed code and not on inserted. > > > Example > > > 1) original HTML > > ... > > <div id="testId"> > > <span id="subId"></span> > > <script> > > $(document).ready(function() { > > $('#subId').append('Some HTML'); > > } > > </script> > > </div> > > ... > > > 2) in AJAX callback load new version of 'tesId' element (with other > > content) from server > > > newVersion = > > <div id="testId"> > > <span id="subId"></span> > > some text > > <script> > > $(document).ready(function() { > > $('#subId').append('Some HTML'); > > } > > </script> > > </div> > > > and then call raplace it > > > $('#testId').replaceWith(newVersion); > > > 3) in result the JS code is evaluated on original element because is > > called > > > after() with result > > > <div id="testId"> -- original > > <span id="subId"></span> > > <script> > > $(document).ready(function() { > > $('#subId').append('Some HTML'); > > } > > </script> > > </div> > > <div id="testId"> -- new version > > <span id="subId"></span> > > some text > > <script> > > $(document).ready(function() { -- new evaluated script > > $('#subId').append('Some HTML'); > > } > > </script> > > </div> > > > then evaluated new version JS part which find and evaluate on first > > (original) 'subId' element and calling remove() remove whole original > > element. > > > What about prefer "before(HTML).remove()" implementation which is > > equivalent and works fine in this type of use. Looking at > > implemenetation of before/after methods: > > > before: this.parentNode.insertBefore( elem, this ); > > after: this.parentNode.insertBefore( elem, this.nextSibling ); > > > 'after has 1 operation more -> 'before' can be bit faster. > > > I don't know how is implemented DOM trees in browsers. If list of sub > > elements is like: > > > 1) linked list - no penalty of inserting element to any place (in may > > opinion is this right) > > 2) array list - bit slower inserting item on -1 place > > > Is this right request for enhancement in next jQuery releases? > > > In our project we will use before(HTML).remove() since :-(. > > > Thank's for such great library > > Zdenek --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---
