Working with AJAX, I encountered the following problem:
http://jsbin.com/iriquf/1
data variable is a basic representation of HTML string.
AJAX returns similar string, but with whitespaces (usually).
So, I tried to look up <h1 /> inside the retrieved AJAX data, but, without dummy element I couldn’t manage to do it.
Is there a better way than wrapping the string into a dummy element?
Use instead
since
$(data)is a jQuery wrapped collection returning[h1, h2, p, div]you can address theh1element with$(data).eq(0)example jsbin: http://jsbin.com/iriquf/3/edit
Otherwise if you don’t know the index of
<h1>element in your collection, make a simple loop to find it(but I strongly prefer the dummy wrapper to this method)