Reputation: 399
I am producing an image tag <img>
inside div dynamically from database by fetching
. My html looks like below :-
<div class='forimgbox'>
<p class='palheading'>Pals</p>
<img src='userpic/2232323.png' width='80px' height='100px'>
<img src='userpic/44542.png' width='80px' height='100px'>
<img src='userpic/88282.png' width='80px' height='100px'>
<img src='userpic/67788.png' width='80px' height='100px'>
<img src='userpic/567886.png' width='80px' height='100px'>
<img src='userpic/456788.png' width='80px' height='100px'>
<img src='userpic/355667.png' width='80px' height='100px'>
</div>
Now the thing what I wanna do is I want to remove some <img>
tag from that parent div by using jquery.I wanna make that jquery works like that it keep '6' <img>
starting from top and then remove or delete every <img>
tag which are produced after 6th <img>
tag from database.Can we do that guys?I thought that it is possible like counting the number of <img>
tag of that parent div
and remove every <img>
tag after '6th' <img>
tag.Please help needed.
Upvotes: 1
Views: 83
Reputation: 6992
for calculate length :
console.log($(".forimgbox img").length)
for remove
$(".forimgbox img:gt(5)").remove()
Upvotes: 1
Reputation: 25527
You can use :gt()
selector for that,
$(".forimgbox img:gt(5)").remove();
It is an index based approach, :gt(5) selector will select all the elements with index greater than 5.(note that, index are counting from 0).
Upvotes: 2