I am trying to extract an element from an AJAX download page so that later it can be added to the DOM. I'm getting the page like this:
$ .ajax ({url: pagePath, success: function) {// data is shown correctly in debugger, all Elements exist. $ Div = $ (data) .find ("[data-custom-attr]"). First (); // $ (data) is length; 0, although the length of $ div is 0! // $ (Data) .find ("#jjpagepage") also has 0 length!}, Datatype: "html"}); This is the received page:
I have tried with some different selectors and everyone fails. I think there should be a really silly mistake somewhere in the code, but can not see it.
What is the problem with those selectors?
The reason for this is that jQuery throws all the nonsense given by you, and only H2 Parsing the div with:
$ ("> DOCTYPE html> gt; & lt; html & gt; & lt; head & gt; & lt; / head & gt; ; & Lt; body & gt; & lt; div id = 'ajaxpage' data-custom-attr = 'ajaxpage' & gt; & lt; h2 & gt; Ajax download page!
> $ ("& lt; div id = 'ajaxpage' data-custom-attr = ' Ajaxpage '& gt; h2 & gt; Ajax download page! & Lt; / h2 & gt; & lt; / div & gt; ") ($ jQuery "...") floods Do not make document documents, it will only create dom pieces)
Because the first element is already your div, you have to be in the [data-custom-entry] subtree, So the result will be []. If you do search ("H2") then it will work fine, because it is in the subtitle of your div, but you find Can not div yourself
No comments:
Post a Comment