') do? I saw this in jQuery tools in a hint script. What is a
? I have never seen a backslash used like this. You wil...">

What does $ ('<div / ">') do?

I saw this in jQuery tools in a hint script. What is a <div/> ? I have never seen a backslash used like this. You will probably get a few votes, but I should know.

+4
source share
1 answer

He used to create the div element. Its short abbreviation to <div></div> .

For instance:

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

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

Demo

More details

This means "create a div element wrapped with jQuery on the fly."

If the parameter has a single tag, for example $('<div />') or $('<a></a>') , jQuery creates the element using its own JavaScript createElement() .

As a result, it will look like this:

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

See here for more details.

+12
source

All Articles