Thursday, April 21, 2011

JQuery clone elements

TASK:
Clone DOM elements.

SOLUTION:
Use .clone() and .appendTo().

EXPLANATION:

In the following example we copy DOM element ".from_to_copy" to ".where_to_copy" without typed data and without javascript's bindings.

JQuery
$(".from_to_copy").clone().appendTo(".where_to_copy");

In this example we copy DOM element with data typed and javascript's bindigs.
JQuery
$(".from_to_copy").clone(true).appendTo(".where_to_copy");

Just change default ".clone()" to ".clone(true)".

2 comments:

  1. SISGAIN offers innovative telemedicine app design services in Saudi Arabia, focused on creating intuitive, user-friendly, and secure digital healthcare platforms. Our design approach prioritizes seamless navigation, patient engagement, and a smooth user experience for both patients and healthcare providers.

    ReplyDelete