Restrict getElementByTagName?

I know I could do child nodes and then test to see if it the the right none name, but am begin lazy. Is there a way to limit getElementByTagName to only child elements (as opposed to all descendants) ?

Without using jQuery (and don’t bother if this is the only reason, or one of just a few reasons, to use jQuery), what you describe is AFAIK the only way.

querySelectorAll seems a good option. I think it’s IE8+ so it should be safe to use.

var childParagraphs = document.querySelectorAll(‘#some-parent-node > p’);

querySelectorAll seems a good option. I think it’s IE8+ so it should be safe to use.

I had forgotten about that one… do you know how far back it works in Webkit and Mozilla?

If the MDN page is right, then since Chrome 1 and FF 3.5. It’s been there for a good while. IE was the holdup.

According to a link I found today querySelectorAll works for all but these selectors in IE8.

:root
:nth-child(1)
:nth-last-child(1)
:nth-of-type(1)
:nth-last-of-type(1)
:last-child
:first-of-type
:last-of-type
:only-child
:only-of-type
:empty
:target
:enabled
:disabled
:checked
:selection
:not(div)

http://stackoverflow.com/questions/21189271/which-standard-css-selectors-are-supported-in-ie8s-queryselectorall

I thought I’d leave the smileys in:)