Click here to Skip to main content
11,487,979 members (79,602 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: HTML jQuery DOM
Hi all!
I have an problem with my project:
i want remove the first class in my dom:
<div id="bottom_main">
  <div class="a"><div>
  <div class="a"><div>
  <div class="b"></div>
  <div class="b"></div>
  <div class="c"></div>
  <div class="c"></div>
</div>
My code is duplicate, so i want to remove the second element or the first element of duplicate class.
Please help me!
Posted 18-Dec-11 22:56pm
Edited 18-Dec-11 23:03pm
Mehdi Gholam276.1K
v2
Comments
SAKryukov at 19-Dec-11 4:10am
   
A class or a div? Both seems straightforward, so, what's the problem?
--SA
SAKryukov at 19-Dec-11 4:12am
   
Also, how come you created the duplicate in first place? If this is a bug, just fix it.
--SA
NguyenVanDuc at 19-Dec-11 23:16pm
   
I want remove all the duplicate div
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

jQuery's "unique" function may help you here.

link[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I'm using .slice() and .remove() of Jquery.
$(".a").slice(0, 1).remove();--> Remove only the second div with class ".a"
$(".a").slice(a, b).remove()--> Remove all div with class ".a" from a to b.
$(".b").slice(0, 1).remove();
$(".c").slice(0, 1).remove();
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,308
1 OriginalGriff 8,352
2 Sascha Lefèvre 3,334
3 Maciej Los 2,956
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web01 | 2.8.150520.1 | Last Updated 3 Jan 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100