Click here to Skip to main content
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
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 OriginalGriff 277
1 Maciej Los 240
2 DamithSL 200
3 Raul Iloc 185
4 Richard MacCutchan 175
0 OriginalGriff 5,130
1 DamithSL 4,197
2 Maciej Los 3,670
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,821


Advertise | Privacy | Mobile
Web02 | 2.8.141216.1 | Last Updated 3 Jan 2012
Copyright © CodeProject, 1999-2014
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