I have this piece of html:
Text for div 2
You should store it this way:
$.ajax({
url: "htmlsnippet.html",
cache: false,
async: false,
dataType: "html",
success: function(data){
html = data;
}
}
EDIT: Your way of obtaining html works, but it's not recommended.
You can't grab your last element because you're using filter
instead of find
, so you should have:
var htmlFiltered = $(html).find("#1 .text");
instead of
var htmlFiltered = $(html).filter("#1 .text");
Also W3C recommends not to have numeric IDs.
EDIT 2: This should work:
var htmlFiltered = $(html).filter("#1").find(".text");
Hope this helps. Cheers