-->

28 April 2021

jQuery selected Selector

  Asp.Net CS By Example       28 April 2021
jQuery selected Selector

 In this post, We are learn abount jQuery selected Selector. jQuery allow we select elements that have been selected by the user. For example, we might have a list box (that is, a <select> control) in which the user has selected several items. We can match those selected items with the selected selector, like this:

 $("select option:selected") 

 Below code example puts for see above jQuery selected Selector to work by counting the number of items the user has selected in a list box.

jqscript.html
<html>
<head>
 <title>
   Counting selected items
 </title>
 <script src="http://code.jquery.com/jquery-latest.js"></script>
 <script type="text/javascript">
  function count( )
  {
    alert("You selected " +
    $("select option:selected").length
    + " items.");
  }
 </script>
</head>
<body>
 <h1>Counting selected items</h1>
 <form>
  <select size="4" multiple="true">
    <option>Item 1</option>
    <option>Item 2</option>
    <option>Item 3</option>
    <option>Item 4</option>
  </select>
  <br>
  <input type="button"
    value="Count"
    onclick="count( )"
  </input>
 </form> 
</body>
</html>


Output:

logoblog

Thanks for reading jQuery selected Selector

Previous
« Prev Post

No comments:

Post a Comment

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