i have problem when i want to get id in li element and stored in temporary document.
this is my javascript code.
var tempNode = document.createElement("div"); //creating element for storing response
tempNode.innerHTML=ajaxhttp.responseText;
var nodes = tempNode.getElementsByTagName("div");
ajaxhttp.responseText equals to
<div id="side">
.....
parent
parent
</div>
</li>
<li id="recent-posts-3" class="widget widget_recent_entries"> <h2 class="widgettitle">fdfs</h2>
<ul>
<li><a href="example.com2011/11/16/43422/" title="fdsdfしい! モsdf モバイルdsf</a></li>
</ul>
</li>
<li id="text-7" class="widget widget_text">
......
</div>
i’m sory if too much but that is my problem.
when i try to loop and get id with this code
for (n=0; n<nodes.length; n++) {
console.log(tempNode.getElementById('recent-posts-3'));
}
the error is not function.and when i try to document.getElementById('recent-posts-3'); the error is same. how i can fixed this problem?
note :
if in my tempNode only this
<li id="recent-posts-3" class="widget widget_recent_entries"> <h2 class="widgettitle">fdfs</h2>
<ul>
<li><a href="example.com2011/11/16/43422/" title="fdsdfしい! モsdf モバイルdsf</a></li>
</ul>
</li>
that’s work. but not in my case i want to all element.
2.and i’m not use jquery i want pure javascript.
getElementById is a method of document, but you use it on a element
You may use element.querySelector() instead: