I am loading pages via ajax and need to grab a certain class from the parsed html. The method I’m using doesn’t seem to work and only returns ‘undefined’.
$.ajax({
type:'post',
url:"path/to/page",
success:function(r){
r = $(r);//parse html
var page = r.find('#siteWrap').attr('class');//pull off class name
alert(page);//returns "undefined"
}
});
Love some help guys!
I solution I came up with (inspired by @helle):
I put a new element on the page I am requesting,
I then use jQuery to pull the html out from between those tags in the response data:
Conclusion:
You can not pull attributes or class names from ajax html responses once parsed by jquery, only html() can be pull out of parsed html data.
Hope this helps someone out!