Все браузеры, кроме IE<9, поддерживают свойство nextElementSibling, следовательно, определяем функцию, в зависимости от того, поддерживается это свойство или нет:
Код
var getNextElement = document.documentElement.nextElementSibling !== undefined ? function(elem) { return elem.nextElementSibling; }:function(elem) { var current = elem.nextSibling; while(current && current.nodeType != 1) { current = current.nextSibling; } return current; };
Пользоваться так:
Код
<div id="id1">Здесь располагается содержимое нового тега Div</div> <!-- комментарий... --> <p>Здесь располагается содержимое нового тега P</p> <script type="text/javascript"> var getNextElement = document.documentElement.nextElementSibling !== undefined ? function(elem) { return elem.nextElementSibling; }:function(elem) { var current = elem.nextSibling; while(current && current.nodeType != 1) { current = current.nextSibling; } return current; }; alert(getNextElement(document.getElementById('id1')).tagName); // alert P </script>