How jquery gets the current Li element is the first few

Source: Internet
Author: User

How does jquery get the current Li element, which is the first number?

User asked:

For example, there is a list of Li, if you know the current Li is the first few Li elements:
<ul>
<li></li>
<li></li>
<li></li>
</ul>
Structure like this, how do I know the current operation of Li is the first few

Solution Case:

<! DOCTYPE html> 
<meta charset= "Utf-8" >&NBSP;
< Meta name= "Author" content= "http://www.45it.com/"/> 
<title> ant tribe </title> 
< Style type= "Text/css" >  
ul{ 
  list-style:none; 
  width:100px; 
  height:25px; 
  line-height:25px; 
  font-size:12px; 

</STYLE>&NBSP;&NBSP
<script type= "Text/javascript" >&NBSP;&NBSP;&NBSP;
Window.onload=function () { 
  var Obox=document.getelementbyid ("box");  
  var Oshow=document.getelementbyid (" Show ");  
  var lis=obox.getelementsbytagname (" Li ");  
  for (Var index=0;index< lis.length;index++) { 
    lis[index].theindex=index; 
    lis[ Index].onclick=function () { 
      oshow.innerhtml=this. theindex; 
   } 
 } 

</script>  
</HEAD>&NBSP
<body> 
<div> Order of the current element: <span id= "Show" ></span></div> &NBSP
<ul id= "box" >&NBSP;
  <li> ant tribe </li> 
  <li> Ant tribe two </li > 
  <li> ant tribe three </li> 
  <li> Ant tribe four </li> 
  <li > Ant Tribe five </li> 
  <li> ant tribe six </li> 
</ul> 
</body> &NBSP

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.