[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Find function skips duplicates

Posted on 2010-08-20
3
Medium Priority
?
291 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
The viewer will learn how to dynamically set the form action using jQuery.
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…
Suggested Courses

649 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