Solved

Find function skips duplicates

Posted on 2010-08-20
3
288 Views
Last Modified: 2012-05-10
Hi,

I have a div like this:

 <div id="hintdata"><div class='10003137'>Key Skills Level 3</div><div class='10003162'>Key Skills Level 3</div><div class='10003198'>Key Skills Level 3</div><div class='10030463'>Hairdressing</div><div class='10030475'>Hairdressing</div><div class='10038310'>Key Skills Level 3</div><div class='10038358'>Key Skills Level 3</div><div class='10038395'>Key Skills Level 3</div><div class='10058722'>Food level 2</div><div class='10064588'>Additional Maths</div><div class='10064588'>Additional Maths test100510</div><div class='50018048'>Welsh bacc Level 3</div><div class='50018073'>Art and Design</div><div class='50018097'>Art and Design</div><div class='50018103'>Art and Design</div><div class='50020481'>Food level 2</div><div class='50036725'>Travel and Tourism Year 12</div><div class='50036725'>Travel and Tourism Year 13</div><div class='50042555'>History of Art</div><div class='50067540'>Food Level 1</div></div></div>

Open in new window


and when I run this in firebug: $('#hintdata').find('div').each(function(index,element){
console.log($(element).text());
})

it does not return the div's with the same number.:

[div.10003137, div.10003162, div.10003198, div.10030463, div.10030475, div.10038310, div.10038358, div.10038395, div.10058722, div.50018048, div.50018073, div.50018097, div.50018103, div.50020481, div.50042555, div.50067540]

Open in new window



I would like to aggregate each div so that for example :

<div class='10064588'>Additional Maths</div> <div class='10064588'>Additional Maths test100510</div>

is edited to:
[code]
<div class='10064588'>Additional Maths<br />Additional Maths test100510</div> 

Open in new window

How would this be done?

Darren
0
Comment
Question by:darren-w-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33484387
Check this :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		var classes = [];
		$("div","#hintdata").each(function() {
			var c = $(this).attr("className");
			if(classes[c]) {
				$("div."+c).append("<br />"+ $(this).html());
				$(this).remove();
			}
			else {
				classes[c] = true;
			}
		});
                // checking
		//alert( $(".10064586").html() );
	});
</script>
</head>
<body>
<div id="hintdata">
<div class='10064588'>Additional Maths1</div><div class='10064588'>Additional Maths1 test1</div>
<div class='10064587'>Additional Maths2</div><div class='10064587'>Additional Maths2 test2</div>
<div class='10064586'>Additional Maths3</div><div class='10064586'>Additional Maths3 test3</div>
<div class='10064585'>Additional Maths4</div><div class='10064585'>Additional Maths4 test4</div>
<div class='10064584'>Additional Maths5</div><div class='10064584'>Additional Maths5 test5</div>
</div>
</body>
</html>

Open in new window

0
 
LVL 13

Author Closing Comment

by:darren-w-
ID: 33484779
That worked great, thanks Darren
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33484792
You're welcome! Thanks for the points!
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question