JQUERY AJAX For Each Loop Custom Attributes
This question is related to another one I asked yesterday and its link is: Parse HTML in jquery through ajax into elements and replace each corresponding on page Basically i want t
Solution 1:
Use attr for custom attribute instead of using this.id
you can use $(this).attr("YourAttr")
;
$(data ).filter('.maindiv').each(function (index)
/* "this" is the current div in response*/
$('#'+$(this).attr('gid')).replaceWith(this);
});
Solution 2:
You can select node with a gid attribute with:
$('[gid]').replaceWith(this);
you can even be more precise by selecting only the node which has the gid value you want
$('[gid="hello"]').replaceWith(this);
Hope it helps
Solution 3:
For data you can use a custom attribute. HTML5 specificies the use of a data-
attribute. The cool thing is that this works in HTML4 too! jQuery can read it by using the data method.
I'll recommend:
<div class="maindiv" data-grid="myGrid">...</div>
$(data).filter('.maindiv').each(function (index)
$('#'+$(this).data('gid')).replaceWith(this);
});
Post a Comment for "JQUERY AJAX For Each Loop Custom Attributes"