B
benjamin
I'm new at JS and DOM, so please bear with me... Here's what I'm trying
to do:
My code is such as this:
***
<div class="post" id="123">
lorem ipsum
<div class="tag1">hello</div>
</div>
***
I'm trying to figure out a function that would spit out the id of every
div that contains the "tag1" div.
I tried the following, by changing the "hello" line in the code above
to:
<div class="tag1" id="456" onClick="saymyclass('456')">this is the tag
text</div>
***
function saymyclass(id){
identity=document.getElementById(id);
alert(identity.className);
alert(identity.parentElement.className);
}
***
The first msg box returns, like expected, "tag1", but the second one
throws this error:
***
Error: identity.parentElement has no properties
***
Any help would be GREATLY appreciated!!
Thanks
to do:
My code is such as this:
***
<div class="post" id="123">
lorem ipsum
<div class="tag1">hello</div>
</div>
***
I'm trying to figure out a function that would spit out the id of every
div that contains the "tag1" div.
I tried the following, by changing the "hello" line in the code above
to:
<div class="tag1" id="456" onClick="saymyclass('456')">this is the tag
text</div>
***
function saymyclass(id){
identity=document.getElementById(id);
alert(identity.className);
alert(identity.parentElement.className);
}
***
The first msg box returns, like expected, "tag1", but the second one
throws this error:
***
Error: identity.parentElement has no properties
***
Any help would be GREATLY appreciated!!
Thanks