I've been thinking about why we cannot do this in javascript.
document.getElementsByClassName('class1').getElementsByClassName('class2')
This will not work, because the first getElementsByClassName
call will give us an HTMLCollection, which doesn't have getElementsByClassName
defined on it. Why is this? This would be a great function to use in this way, since it would let you get elements based on them having multiple different classes, not just one.
Is there any way to:
- Get elements by class name in HTMLCollection
- Get elements by multiple class names