0

I dynamicly get divs at the end of an ajax call. Some of those divs have the same html content. I wish to write a code that will display only one div per unique content.

Find divs with the same content and only display one of them. So far I have:

onAjaxComplete: function () {

    $("div.autocomplete-suggestions > .autocomplete-suggestion").each(function() {

        while ($(this).html()) {

            //DO SOMETHING HERE       
    }
});

autocomplete-suggestion is a class name of my divs with the same content.

LazyPeon
  • 339
  • 1
  • 19
  • 1
    hope below answer will help you [click here][1] [1]: http://stackoverflow.com/questions/2822962/jquery-remove-duplicate-elements – Feroza Sep 24 '14 at 11:38

1 Answers1

1
//include this function at the top
 function contentInArray(arr,thing){
     for(var i=0;i<arr.length;i++){ 
         if (arr[i].innerHTML==thing.innerHTML)return true;
     }
     return false;
 }
  //code code code code code

  onAjaxComplete: function () {
    divs=$("div.autocomplete-suggestions > .autocomplete-suggestion");
    arr=[];
    for(var i=0;i<divs.length;i++){
        if (!contentInArray(arr,divs[i])) arr.push(divs[i])
    }
});

Now you have an array of html elements of unique content

Nick Manning
  • 2,828
  • 1
  • 29
  • 50