Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Selector inside of variable?

Hi I'm trying to get the IDs of all DIVs, inside another HTML File, with a specific Class. To load the file I use:

$.get("blocks.html", function(data) {
        //here I don't know how :)
});

Now what I'm looking for ist something like this:

data.$('.block').each(... the rest is no problem

so that I use the jQuery selectors not on my page code but instead inside the contend of the data variable. Thanks for help!

like image 975
Simon Appelt Avatar asked May 16 '13 14:05

Simon Appelt


2 Answers

$.get("blocks.html", function(data) {
    var ids = $('<div/>').html(data).find('div.block').map(function() {
        return this.id;
    }).get();
});
like image 77
undefined Avatar answered Oct 19 '22 00:10

undefined


Try this:

$.get("blocks.html", function(data) {
        $(data).find('.block').each(function(){...});
});

If your 'data html' containing element is a '.block', look at @undefined's answer

like image 8
A. Wolff Avatar answered Oct 19 '22 00:10

A. Wolff