Reputation: 11
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<p class="myChild">one</p>
<p class="myChild">two</p>
<p class="myChild">three</p>
<script>
$(document).ready(function(){
//code that selects the second and the third myChild class name
});
</script>
</body>
</html>
here i have 3 p tags with myChild class, i want to select the second and the last one using jQuery to do that, and know how to manipulate with that
Upvotes: 1
Views: 94
Reputation: 693
$(".myChild")
will return a HTMLCollection
(sort of like an array) of objects - you can iterate though this or directly reference positions in that collection. e.g. $(".myChild").eq(1)
for the 2nd items and $(".myChild").eq(2)
for the 3rd item.
Upvotes: 0
Reputation: 10874
just use the not filter and pass it eq(0) which is basically stripping out the first result
$('.myChild').not(':eq(0)');
or for the shortest way and using only the selector engine
$('.myChild:not(:eq(0))')
Fiddle here http://jsfiddle.net/D5Ngh/
Upvotes: 1
Reputation: 4368
If you are checking for the remaining except first one, you can use :not(0)
Upvotes: 0
Reputation: 337713
Use slice()
to select a subset of results:
$(".myChild").slice(1);
This will remove the first myChild
element and return the rest.
If you want to specify a start and end point to slice at then you supply two parameters:
$(".myChild").slice(1,3);
Upvotes: 1