How can I get all children (i.e. children of children) using Javascript?

I need a javascript or CSS Selector function (or even a ProtoypeJS function ) that gets me ALL elements (i.e. descendants) under a specific element.

I understand that there is a CSS selector, such as: 'p, a, div' , which will give me all the elements of these three types. However, I need to get EVERYTHING without specifying a type.

T. I want something like

myElement.getElements('*')
+3
source share
4 answers

Compatible with all versions of IE, not just IE8 + ...

myElement.getElementsByTagName("*")

* getElementsByTagName . ( querySelectorAll, * , )

+4

querySelectorAll

myElement.querySelectorAll('*')

: IE8 +

+5

, PrototypeJS, childElements() http://api.prototypejs.org/dom/Element/prototype/childElements/

element.childElements()

, select()

element.select('div')

div element

+1

CSS. * () . element, :

element * {}
0

All Articles