Demo: http://jsfiddle.net/ThinkingStiff/y9K9Y/
If the <div>
you're searching for has a class, you can use getElementsByClassName()
:
document.getElementById( 'parentDiv' ).getElementsByClassName( 'childDiv' )[0];
If it doesn't have a class you can use getElementsByTagName()
:
document.getElementById( 'parentDiv' ).getElementsByTagName( 'div' )[0];
And if it has an id
you can, of course, just use getElementById()
to find it no matter where it is in the DOM:
document.getElementById( 'childDiv' );
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…