Monday, September 27, 2010

How to get all children of an html element working in IE and Firefox

var children = document.getElementById('myId').childNodes;
// or
var children = document.getElementById('myId').getElementsByTagName('*');

the first returns the list of direct descendants, but the second one returns a list of all descendants.

There are some differences between IE and Firefox when interpreting javascript like:
document.all does not work in firefox.(we should always use document.getElementById('blah'); )
To get control innerText, for IE there is innerText property and for firefox, there is textContent,
so it is better to user innerHtml that works for both.


Mike said...

great ..let me check it. I am hoping I will get all children of an html element using it. It is looking to be too useful query.
what is a digital signature

Post a Comment