dom - Loading Specific Content from another page using Javascript -


index.html  <script > function loadpage(){     var xhttp,rtext,x;     xhttp=new xmlhttprequest();     xhttp.onreadystatechange=function(){         if (xhttp.readystate == 4 && xhttp.status == 200) {            rtext=xhttp.responsetext;             x = rtext.getelementbyid('bottom');         }         document.getelementbyid("firstdiv").innerhtml=x;     };     xhttp.open("get","first.html",true);     xhttp.send(); }   </script>     <body>     <div onclick="loadpage();">home</div>     <div id="firstdiv"></div>     </body>    first.html      <body>     <div id="bottom">     <p>content 1</p>      </div>     <div id="bottom1">     content 2     </div>     </body> 

i need load "bottom" div first.html index page using javascript , facing error.

getelementbyid('bottom') not define property .

how proceed ?

try creating new document contents of 'first.html', query document element want.

var doc = document.implementation.createhtmldocument("doc title"); doc.body.outerhtml = rtext; var bottom = doc.getelementbyid('bottom'); 

not tested, place start.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -