Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a div element in jQuery [duplicate]

How do I create a div element in jQuery?

like image 200
useranon Avatar asked May 15 '09 10:05

useranon


People also ask

How do I clone a div?

To clone a div and change its id with JavaScript, we can use the cloneNode method on the div. Then we can set the id property of the cloned element to set the ID. to add the div.

How do you copy the content of a div into another div using jQuery?

First, select the div element which need to be copy into another div element. Select the target element where div element is copied. Use the appendTo() method to copy the element as its child.

How can I duplicate a div onclick event?

To duplicate a div onclick event with JavaScript, we can call cloneNode` to clone an element. Then we can set the onclick property of the cloned element to the same event handler function as the original element. to add a div. Then we deep clone the element by calling cloneNode with true .

How can I create duplicate row in jQuery?

Call the . clone() method on the selector which you want to copy and insert the newly created element in your existing HTML layout using append, pretend, insertAfter, etc. $( ". txt").


1 Answers

As of jQuery 1.4 you can pass attributes to a self-closed element like so:

jQuery('<div>', {     id: 'some-id',     class: 'some-class some-other-class',     title: 'now this div has a title!' }).appendTo('#mySelector'); 

Here it is in the Docs

Examples can be found at jQuery 1.4 Released: The 15 New Features you Must Know .

like image 124
ian Avatar answered Sep 18 '22 11:09

ian