In jquery what does $('<div></div>') do?

I was implementing a jqueryui modal dialog box and a related blog showed a way of implementing it that worked but I don't understand what $("<div></div>") is actually doing. Is this creating a blank div element to use? Is this a safe way of implementing this?

Answers


It's equivalent to document.createElement('DIV').

You can look at the jQuery source. Look for the comment:

// Handle HTML strings

And you'll see how it works.

The <div> created is empty, has no attributes, and is not attached to the DOM.

It's more common to see it written as:

$('<div />')

...but not functionally different.

Often it's chained with a method like appendTo(), to insert it into the DOM.


Need Your Help

Interaction between Java and C#

c# java programming-languages user-interface

Is it possible to write a user interface in Java for an application written in C#?

Changing file descriptor limit in C (OSX)

c osx file-descriptor setrlimit

I want to increase the maximum number of file descriptors available to my C program, which is running on OSX 10.7. I've added the following code to my project, but it fails!

Using a Join with Grouped Data Rows

mysql database join left-join

I have two tables, invoices and deposits.