How to get all elements between html tag?

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.

Answers


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')


You 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)
});

Need Your Help

Accessing MySQL relations with Ruby on Rails

mysql ruby-on-rails

How do you access a MySQL relation using RoR?

parse add multiple images to an array after loop

ios iphone arrays swift parse.com

I have an item Object which has a relation class which contain several images related to the item. The problem is I'm trying to add these images to an array so first inside the loop I'm adding them...