Forum Moderators: open
I was looking for a way to insertAfter however it was all copy and paste without examples...worse none of it seemed to reference element id's.
That has led me to nextSibling. What I'm trying to do is figure out how to reference the next element's id attribute value. For example...
<div id="el1">element 1</div>
<div id="el2">element 2</div>
var parent = el1;
alert(parent + ' == ' + document.getElementById(parent).firstChild.nodeValue);
To dynamically determine the next element's id (as in not statically setting an id) I have been trying stuff like this...
alert(document.getElementById(parent).nextSibling.id);
That does not work...the desired result would alert 'el2' from the above XHTML. So all I want to do is alert the following element's id. Suggestions please?
- John
<div id="el1">element 1</div>
<div id="el2">element 2</div>
var parent = el1;
alert(parent + ' == ' + document.getElementById(parent).firstChild.nodeValue);
alert(document.getElementById(parent).nextSibling.id);
Setting parent to eaqual el1 like that would refer to the object el1. That's not the right parameter to pass to getElementById, did you mean to quote it as a string?
var parent = "el1";
Not sure what you're setting parent to in your dynamic function, maybe just a simple mistake?
I'm going to try and create some variations in the XHTML code and try to see if it's a pattern for Gecko/Opera/WebKit versus IE's interpretation or if it's going to be too goofy to be reliable to become part of a reusable function.
- John