-->

28 April 2021

jQuery Position Selector

  Asp.Net CS By Example       28 April 2021
jQuery to select Elements by Position Selector

 In this post, we are learning about jQuery to select Elements by Position Selector. jQuery allows we select page elements by their position in a page in jQuery. For example, we can select all <p> elements in a page with Position selector:

 $("p") 

 If we want only the second <p> element, however, we can select it like this:

 $("p:eq(1)") 

Note that the page index number is zero based (that is, page index numbers begin at zero), so the second <p>> element corresponds to index 1.

 Below code example puts for see above jQuery to select Elements by Position Selector working.

jqscript.html
<html>
<head>
 <title>
   Selecting one of a set
 </title>
 <script src="http://code.jquery.com/jquery-latest.js"></script>
 <script type="text/javascript">
  function checkType( )
  {
    $("p:eq(1)").css("font-style", "italic");
  }
 </script>
</head>
<body>
 <h1> Selecting one of a set</h1>
 <div>
   <p id="p1">This is paragraph 1.</p>
   <p id="p2">यह पैरा 2 है.</p>
   <p id="p3">हा परिच्छेद 3 आहे.</p>
   <p id="p4">This is paragraph 4.</p>
 </div>
 <form>
  <input type="button"
    value="Select"
    onclick="checkType()"
  </input>
 </form> 
</body>
</html>


Output:

logoblog

Thanks for reading jQuery Position Selector

Previous
« Prev Post

No comments:

Post a Comment

Please do not enter any spam link in the comment box.