0

I need to compare all the selected attribute with variants on the AliExpress site.But my code is checking for only first key and adding class but when its come to 2nd and 3rd class its look like its not checking for them.I tried using length property but it says length is undefined.

function selectAttributes() {
  chrome.storage.local.get(null, function(result) {
    for (i = 0; i < result.ae_items.length; i++) {
      console.log(result.ae_items[i].attributes);
      for (var key in result.ae_items[i].attributes) {
        $(".sku-property-list").each(function() {
          $(".sku-property-item").each(function() {
            if ($(this).has("img")) {
              var title = $(this).children(".sku-property-image").children("img").attr("title");
              if (title == result.ae_items[i].attributes[key]) {
                $(this).addClass("selected");
              }
            } else {
              var title = $(this).children(".sku-property-text").children("span").text();
              alert(title);
            }
          });
        });
      }
    }
  });
}

attribute object

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Maaz Khan
  • 21
  • 1
  • 7
  • Does this answer your question? [How can I check that two objects have the same set of property names?](https://stackoverflow.com/questions/14368596/how-can-i-check-that-two-objects-have-the-same-set-of-property-names) – norbitrial Apr 10 '20 at 13:59
  • no beacuse i need to compare with li using contenyscript – Maaz Khan Apr 10 '20 at 14:07

1 Answers1

0

This is comparing all the keys of object but the issue was with else block. Else block was not executing so I tried different ways and finally came out with decision that no need to use else block. Its working after removing else block

Maaz Khan
  • 21
  • 1
  • 7