Click here to Skip to main content
11,935,053 members (54,381 online)
Rate this:
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>
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 Gholam292.8K
SAKryukov 19-Dec-11 4:10am
A class or a div? Both seems straightforward, so, what's the problem?
SAKryukov 19-Dec-11 4:12am
Also, how come you created the duplicate in first place? If this is a bug, just fix it.
NguyenVanDuc 19-Dec-11 23:16pm
I want remove all the duplicate div
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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

Rate this: bad
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();

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web03 | 2.8.151126.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