The answer really depends on what the responseText looks like that is being returned from the GET request. Based on that you would have to wrap it or not.
With Parent
If the response is nested inside of a parent tag.
Response Mark Up:
<div>
<div id="someId1"></div>
<div id="yourId" class="block"></div>
<div id="someId2"></div>
</div>
JavaScript:
var htmlFiltered = $(html).find('.block');
Without Parent
If the response does not have a parent node wrapping the content, you would need to add the parent node or use filter.
Response Mark Up:
<div id="someId1"></div>
<div id="yourId" class="block"></div>
<div id="someId2"></div>
JavaScript:
var htmlFiltered = $(data).filter('.block');
or
var htmlFiltered = $("<div/>").html(data).find('.block');
Getting the ids
You can than use map()
or each()
on htmlFiltered
to get the ids.
With each()
var ids = [];
htmlFiltered.each( function () {
ids.push(this.id);
});
console.log(ids);
With map()
var ids = $.map(htmlFiltered, function (elem) {
return elem.id;
});
console.log(ids);