0

I'm using Feedburner to show feeds. sometimes the feeds have the same title. In situations where this is the case I would like to show only the first title and hide all the other titles with the same text. I tried this: JsFiddle

No luck. I can refer to them as 'a' but I don't understand how to distinguish them from one another.

Youss
  • 4,196
  • 12
  • 55
  • 109
  • It doesnt show anything in the output – Om3ga Aug 16 '12 at 10:43
  • That't because I have display:none ..... – Youss Aug 16 '12 at 10:44
  • 3
    http://stackoverflow.com/questions/5381621/jquery-function-to-get-all-unique-elements-from-an-array Should help you figure out how to filter unique elements from array of results. – Prasanth Aug 16 '12 at 10:47
  • @goldenparrot Thanks +1, I have tried it at http://jsfiddle.net/NHEKd/2/ I can't seem to 'show' the var unique...maybe you can help me out (answer) – Youss Aug 16 '12 at 10:59

2 Answers2

0

Try starting with all links showing and this javascript:

$(function() {
    var $feeds = $(".feedburnerFeedBlock li a");
    $feeds.each(function(i) {
        var $that = $(this);
        $feeds.each(function(j) {
            var $this = $(this);
            if (j <= i) {
                return true;//continue
            };
            if ($this.text() == $that.text()) {
                $this.hide();
            }
        });
    });
});

DEMO

Beetroot-Beetroot
  • 18,022
  • 3
  • 37
  • 44
0

Instead of using the filter function you could use an object to collect all the feed titles with their jQuery elements. The object will behave just like a HashMap in Java since objects can't contain duplicate keys - so duplicate feed titles are eliminated automatically.

var unique = { };
// Reverse elements to keep first occurence of feed title (and not the last one)
$($(".feedburnerFeedBlock li").get().reverse()).each(function(){
    // Use feed title as key and jQuery element as value
    unique[$(this).find("a").text()] = $(this);
}).hide();
// Show all unique elements
for (title in unique) {
    unique[title].show();
}

JSFiddle: http://jsfiddle.net/Aletheios/9GKBH/1/

Besides, your code doesn't work because of several reasons. Amongst others jQuery's .html() function only returns the HTML string of the first element in the set (see documentation).

Aletheios
  • 3,960
  • 2
  • 33
  • 46