Skip to main content
Queryselector is supported in all major browsers now.
Source Link
jmargolisvt
  • 6.1k
  • 5
  • 32
  • 50

The children property returns an array of elements, like so:

parent = document.querySelector('.parent'); children = parent.children; // [<div class="child1">] 

querySelector is relatively new and not supported in older browsers. There are alternatives to querySelector, like document.getElementsByClassName('parent')[0] if you so desire.


Edit: Now that I think about it, you could just use querySelectorAll to get decendents of parent having a class name of child1:

children = document.querySelectorAll('.parent .child1'); 

The difference between qS and qSA is that the latter returns all elements matching the selector, while the former only returns the first such element.

The children property returns an array of elements, like so:

parent = document.querySelector('.parent'); children = parent.children; // [<div class="child1">] 

querySelector is relatively new and not supported in older browsers. There are alternatives, like document.getElementsByClassName('parent')[0] if you so desire.


Edit: Now that I think about it, you could just use querySelectorAll to get decendents of parent having a class name of child1:

children = document.querySelectorAll('.parent .child1'); 

The difference between qS and qSA is that the latter returns all elements matching the selector, while the former only returns the first such element.

The children property returns an array of elements, like so:

parent = document.querySelector('.parent'); children = parent.children; // [<div class="child1">] 

There are alternatives to querySelector, like document.getElementsByClassName('parent')[0] if you so desire.


Edit: Now that I think about it, you could just use querySelectorAll to get decendents of parent having a class name of child1:

children = document.querySelectorAll('.parent .child1'); 

The difference between qS and qSA is that the latter returns all elements matching the selector, while the former only returns the first such element.

added 195 characters in body
Source Link
Rick Viscomi
  • 8.9k
  • 4
  • 42
  • 57

The children property returns an array of elements, like so:

parent = document.querySelector('.parent'); children = parent.children; // [<div class="child1">] 

querySelector is relatively new and not supported in older browsers. There are alternatives, like document.getElementsByClassName('parent')[0] if you so desire.


Edit: Now that I think about it, you could just use querySelectorAll to get decendents of parent having a class name of child1:

children = document.querySelectorAll('.parent .child1'); 

The difference between qS and qSA is that the latter returns all elements matching the selector, while the former only returns the first such element.

The children property returns an array of elements, like so:

parent = document.querySelector('.parent'); children = parent.children; // [<div class="child1">] 

querySelector is relatively new and not supported in older browsers. There are alternatives, like document.getElementsByClassName('parent')[0] if you so desire.

The children property returns an array of elements, like so:

parent = document.querySelector('.parent'); children = parent.children; // [<div class="child1">] 

querySelector is relatively new and not supported in older browsers. There are alternatives, like document.getElementsByClassName('parent')[0] if you so desire.


Edit: Now that I think about it, you could just use querySelectorAll to get decendents of parent having a class name of child1:

children = document.querySelectorAll('.parent .child1'); 

The difference between qS and qSA is that the latter returns all elements matching the selector, while the former only returns the first such element.

Source Link
Rick Viscomi
  • 8.9k
  • 4
  • 42
  • 57

The children property returns an array of elements, like so:

parent = document.querySelector('.parent'); children = parent.children; // [<div class="child1">] 

querySelector is relatively new and not supported in older browsers. There are alternatives, like document.getElementsByClassName('parent')[0] if you so desire.