jQuery Tutorial
slice(start, end-1)
slice method is used to get the specified element from the start index to end index (end index -1). here index starts from zero.
Selects the list of elements as specified index in range.
<html>
<head>
<title>The jQuery Example - To select the list of elements in specified range</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type = "text/javascript">
$(document).ready(function(event) {
$('p').slice(1,4).css('color', 'blue');
});
</script>
</head>
<body>
<p>line 0</p>
<p>line 1</p>
<p>line 2</p>
<p>line 3</p>
<p>line 4</p>
<p>line 5</p>
<p>line 6</p>
</body>
</html>
Output:
Displays the paragraph elements content in blue color from starting index 1 to end index 3 (end index -1).
« Previous Next »
jQuery Tutorial
Privacy Policy | Copyright
2020 - All Rights Reserved. | Contact us
| Report website issues in Github
| Facebook page
| Google+ page