HTML :
<li>Tue, 15th May 2012 10:11</li>
<li>Tue, 15th May 2012 10:12</li>
<li>Tue, 15th May 2012 10:13</li>
<li>Tue, 15th May 2012 10:14</li>
<li>Tue, 15th May 2012 10:15</li>
<li>Tue, 16th May 2012 21:08</li>
<li>Tue, 16th May 2012 21:07</li>
<li>Tue, 16th May 2012 21:06</li>
<code></code>
jQuery :
$("li").each(function () {
words = $(this).text().split(' ');
xxx = words[1]+" "+words[2]+" "+words[3]+",";
$("code").append(xxx);
});
I come to this step now, but i dont know how to check duplicates date and append unique date
Demo : http://jsfiddle.net/4kvUy/
Do this way:-
if ($("code:contains('"+xxx+"')").length == 0)
$("code").append(xxx);
To handle Comma, try this way:-
if ($("code:contains('"+xxx+"')").length == 0){
if ($("code").text() == '')
$("code").append(xxx);
else
$("code").append(","+xxx);
}
To handle this type of output, try this way:-
$("li").each(function () {
words = $(this).text().split(' ');
xxx = words[1]+" "+words[2]+" "+words[3];
if ($("code:contains('"+xxx+"')").length == 0){
if ($("code").text() == '')
$("code").append('["'+xxx);
else
$("code").append('","'+xxx);
}
});
$("code").append('"]');
Output:
["15th May 2012","16th May 2012"]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With