-4

i've seen this, most places on Jquery existing codes.

What is the exact meaning of this..? How it's working..?

Sample Jquery Code

var t=$("<div/>");
t.text("Dynamic Programming");
$("body").append(t);

the above code, working fine..

awaiting responses, thanks in advance !

nnnnnn
  • 147,572
  • 30
  • 200
  • 241
Keerthivasan
  • 1,651
  • 1
  • 21
  • 47

4 Answers4

7

jQuery( html [, ownerDocument ] )

Description: Creates DOM elements on the fly from the provided string of raw HTML.

html
Type: htmlString
A string of HTML to create on the fly. Note that this parses HTML, not XML.

ownerDocument
Type: document
A document in which the new elements will be created.

http://api.jquery.com/jQuery/#jQuery2

So basically $("<div/>") creates a new DIV element.

$("<div/>") is the same as $("<div></div>")

Mike Scotty
  • 10,530
  • 5
  • 38
  • 50
2

By using $('<element>', {options}) you can create new element. E.g.

$('<span>', {'class': 'my-new-class', id: 'some-id', text: 'SPAN'});

you will get this element: <span class="my-new-class" id="some-id">SPAN</span>

Justinas
  • 41,402
  • 5
  • 66
  • 96
1

In this example it means you are telling jQuery to

  1. create a new <div> element
  2. set the text content of the div to "Dynamic Programming"
  3. Append it to the body.

You can refer to the documentation for additional examples and further explanation. For other ways of accomplishing the same thing you can check out this existing answer.

Community
  • 1
  • 1
oligofren
  • 20,744
  • 16
  • 93
  • 180
1

It says, I am creating a div block and add text value. That programmatic ally created div will be append to body. It is used for adding dynamic elements to dom.

omer faruk
  • 350
  • 4
  • 13