Rony
Rony

Reputation: 108

what is the "<li/>" tag for..?

What is the <li/> tag for..?

Can anyone point/find/share some documentation related to it..?

I found the code in this answer by "thecodeparadox"

I have tried hard to find some documentation related to that in vain..

Upvotes: 3

Views: 95

Answers (3)

dashtinejad
dashtinejad

Reputation: 6253

The <li/> tag in jQuery is for tag creation, It's shorthand for <li></li>, in jQuery documentation:

When the parameter has a single tag (with optional closing tag or quick-closing) — $( "<img />" ) or $( "<img>" ), $( "<a></a>" ) or $( "<a>" ) — jQuery creates the element using the native JavaScript .createElement() function.

A basic sample:

$('<li/>').text('Hello World 1').appendTo('ul');
$('<li></li>').text('Hello World 2').appendTo('ul');
$('<li>').text('Hello World 3').appendTo('ul');

See this jsFiddle Demo.

Upvotes: 1

John Hascall
John Hascall

Reputation: 9416

HTML provides tags for constructing ordered <ol> ("numbered") and unordered <ul> ("bulleted") lists.

Each item in such a list is indicated by the <li> tag.

<ul>
  <li>First!</li>
  <li>Second Base</li>
  <li>Three Strikes and you are Out</li>
</ul>

(sadly, often you will see the closing tag </li> omitted) The notation <TAG/> is a shorthand for an empty tag (that is, equivalent to <TAG></TAG>).

There is little use for an empty list item, besides as a placeholder to be expanded upon later by javascript.

Upvotes: 3

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85575

jQuery provides an alternative to the traditional DOM createElement.

$("<li/>"); //create li element

If you wish to modify the element or bind events to it, you can do like below:

$("<li/>", { 
  click: function(){}, //allows you to bind events
  id: "test", // can be set html attribute
  addClass: "clickable" //allows you to bind jquery methods 
});

Documentation can be found here.

Upvotes: 4

Related Questions