Gabriel Burciu
Gabriel Burciu

Reputation: 123

.attr selector wont work in a each loop?

Here's the code:

  $.ajax({
      url: 'AEWService.asmx/previewAsset',
      type: "GET",
      contentType: "application/json; charset=utf-8",
      data: json,
      success: function (json) {
          var prevObj = jQuery.parseJSON(json.d);
          setInterval(function () {
              var pId = $('#previewIframe').contents().find('[preview-id]');
              $.each(prevObj, function (i, item) {
                  pId.each(function () {
                      var pElem = this.attr("preview-id");
                      if (pElem == item.Id) {
                          $(this).html(item.Value);
                      }
                  });
              });
          }, 3000);
      }
  });

Upvotes: 0

Views: 92

Answers (2)

whytobe
whytobe

Reputation: 163

Try to change this.attr("preview-id") to $(this).attr("preview-id")

like you use this in $(this).html(item.Value)

Hope this help you.

Upvotes: 1

Felix Kling
Felix Kling

Reputation: 816384

this is a DOM node, not a jQuery object. Please read the .each() documentation and have a look at the examples.

Actually you already seem to know that, since you are calling $(this).html()...

Upvotes: 5

Related Questions