Assume that in
$.ajax({
url: 'page1.html',
data: {},
success: function (data) {
$(data) //return an array of nodes
},
dataType: 'html'
});
$(data) returns an array of nodes:
[<div id="a">,
<div id="b">, //3 elements
<div id="c">]
and I want to get the HTML of the div that has an id of "b". I tried
$(data).find("#b");
but it returns a blank array. ([]) So how can I select it? Please help.
Use
.filter()to select from top level elements.Use
.find()to selected nested elements.