How to Use Size() method in JQuery
In this article I have described how calculate number of elements attach with a list or any other type of container with the help of JQuery.
Size() method in JQuery
- If we want to calculate number of elements attach with a list or any other type of container, then we use size() method.
- In this context we will use the JQuery Selector.
Syntax
The syntax for this purpose as follows
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
alert($("li").size());
});
});
</script
|
Lets take an Example
<!DOCTYPE html>
<html>
<head>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("button").click(function () {
alert($("li").size());
});
});
</script>
</head>
<body>
<button>Count The Number Of Student</button>
<ol>
<li>Aman</li>
<li>Nitin</li>
<li>Prabhakar</li>
<li>Styaprakash</li>
<li>Vipin</li>
<li>Shubham</li>
<li>Arun</li>
</ol>
</body>
</html>
|
OUTPUT
When we run this program we have the output as follows
When we click on Button
You may also want to read these related articles Click here
Ask Your Question
Got a programming related question? You may want to post your question here
Programming Answers here