Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

jquery

I saw this in jQuery tools in the tooltip script. What is <div/> ? I've never seen the backslash used that way. Probably going to get some down votes, but I must know.

like image 665
domino Avatar asked Jun 10 '12 17:06

domino


People also ask

Does a div do anything?

The <div> tag doesn't technically do anything. It can help organize an HTML file into sections on the back end, but that won't affect how those sections display on the front end. It does, however, allow these sections to be easily styled with CSS.

Why do we use div?

The Div is the most usable tag in web development because it helps us to separate out data in the web page and we can create a particular section for particular data or function in the web pages. It is used to the group of various tags of HTML so that sections can be created and style can be applied to them.

How does a div work?

You use the DIV tag in HTML to divide sections of an HTML document. Using the DIV tag lets you define block-level sections of an HTML document. Applying a DIV tag lets you identify the section defined by the DIV tag, so you can then apply formatting or scripting to its content.


1 Answers

It used to create a div element. Its short cut to <div></div>.

For example:

$('<div/>', {id: 'hello', 'class': 'new', html: 'New div'}).appendTo('#target');

will create div with id: hello, class: new with html New div and append to #target.

DEMO

More details

It means "create a jQuery-wrapped div element on the fly".

When the parameter has a single tag, such as $('<div />') or $('<a></a>'), jQuery creates the element using the native JavaScript createElement() function.

As result it will look like:

$(document.createElement("div"));

For detail see here

like image 108
thecodeparadox Avatar answered Sep 22 '22 12:09

thecodeparadox