I want to get all elements from the web page.i used form id or name to get all elements but if there is no form id or name i can't get elements from that page.what is the alternate for this problem. please help.
I want to get all elements from the web page.i used form id or name to get all elements but if there is no form id or name i can't get elements from that page.what is the alternate for this problem. please help.
Share Improve this question edited Nov 30, 2011 at 6:41 Kiran 20.3k11 gold badges71 silver badges101 bronze badges asked Nov 30, 2011 at 6:36 Manohar Kulanthai velManohar Kulanthai vel 5814 gold badges9 silver badges20 bronze badges 5-
What are you exactly looking for? If you have the
document
surely you have all the elements? – Emond Commented Nov 30, 2011 at 6:41 -
1
$("*")
:-D __________ – Adam Rackis Commented Nov 30, 2011 at 6:42 - @AdamRackis But that assumes jQuery use. Manohar might not be using that. Although, it is the best way to do that :) – Arindam Commented Nov 30, 2011 at 6:44
- I mean all the objects type and name or value – Manohar Kulanthai vel Commented Nov 30, 2011 at 6:44
- @Arindam - I know, hence my smiley face...though from the answers I'm seeing, maybe I should have just put that as an answer – Adam Rackis Commented Nov 30, 2011 at 6:46
5 Answers
Reset to default 6You can retrieve an array of all nodes in a html document using document.getElementsByTagName('*')
. After that you can iterate through that array:
var allElements = document.getElementsByTagName('*');
for (var i=0;i<allElements.length;i++){
//do things with the element, e.g.
//console.log(allElements[i].type)
//console.log(allElements[i].id)
//console.log(allElements[i].innerHTML)
}
Update 2014: a more modern approach would be
var allEls = [].slice.call(document.querySelectorAll('*');
allEls.forEach( function (el) {
//do things with the element, e.g.
//console.log(el.type)
//console.log(el.id)
//console.log(el.innerHTML)
});
You can use jQuery: $("html *")
which will return all elements between the html tags
for names you must use $("html *").attr('name')
for values $("html *").val()
or $("html *").attr('value')
Have heard of something called jQuery ? With the help of traversing API you can get to an element you want. Here is the plete list of API - http://api.jquery./
You can use the jQuery selectors like: $("*") .This particular selector will return all the elements(tags) of that html page.
maybe you can try this: document.childNodes
no framework, lib needed.