I have problems to access elements of a html response of an ajax request. I am using jquery and I try to simplify the problem as much as possible:
I have an ajax html response like this (kept very simply):
<div id="div_1"><span id="span">Text in Span</span></div>
<div id="div_2">Text in div</div>
Now I am trying to access certain elements of this html response with jquery:
$.ajaxSetup(
{
success: function(html)
{
alert($('#span', html).html()); //works fine
alert($('#div_1', html).html()); // doesn't work, why?
alert($('#div_2', html).html()); // also doesn't work
alert( $('span', html).first().attr('id') ); // works fine
}
}
I actually want to get the id of the first div element, but i seems as i cannot access the first "level" of the html response. I probably could solve the problem with a div surrounding container, which contains everything else.
Is there a another solution oder could somebody explain me, why jquery seems to ignore the first level of the html?
Thank you very much and sorry for my english (I am not a native speaker) Phantom