javascript - Unable to re-use element objects? -


It looks like I attach the element object to the page, I can not add it again to the other part of the page . Something strange about this behavior, does anyone know what this is happening and how to know any other element to add the object again? I have tried copying the object to a new variable and it still does not help.

Here the code is: (The object should be added for both div, but only to add the first)

  var $ e = $ ("& lt; a / & Gt; ") .append (" & lt; span & gt; link  ") .attr (" href "," # "). Click (function (e) {e.preventDefault (); Warning ('Hi');}); Var $ e2 = $ e; $ ("Div: First"). Attachments ($ E); $ ("Div: The Last"). Attachments ($ e2);  

HTML:

  & lt; Div & gt; & Lt; / Div & gt; & Lt; Div & gt; & Lt; / Div & gt;  

body:

Each object is unique, $ E2 is just a reference to the created element you should store:

  var $ e2 = $ e.clone ();  

To copy event handlers, you can pass the true to clone method.


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -