473,385 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need to find a div's container div's classname and id

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

Nov 23 '05 #1
2 11488

benjamin wrote:
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);


Should be instead:

identity.parentNode.className

Nov 23 '05 #2
NEVERMIND...
just discovered it was a Firefox/IE deal... I am now using parentNode
instead of parentElement, and it works...

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: lkrubner | last post by:
How do I get all the div's on a page? I realize in IE I can use document.all. For the other browsers, I need to get an array of all the divs on the page. getElementByTagName()?????
1
by: Gernot Frisch | last post by:
I want to center the div "KungFu" over the div "header". Does not. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//DE"> <html> <body> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p>
1
by: asilverpeach | last post by:
Hey Guys! Found some great scripts here on this topic but have to make to changes to the code that I can't seem to figure out. First, In the following code clicking on the headers shows the...
10
by: jon | last post by:
I'm trying to use a hidden iframe to print the contents of one div seamlessly. Currently I can create the hidden iframe, copy the contents of the div to the iframe, and print it. I even have a...
4
by: planb | last post by:
Hi, I'd like to have a rollover like effect when a input field has the focus, any idea of how to do this with just CSS (easy enough with javascript)? What I'm thinking of is having a tips box...
8
by: =?iso-8859-1?q?Jean-S=E9bastien?= | last post by:
Hello, I'm starting in rails and ajax. So i've a javascript question: someone could help me to update the class of a div? Regards.
18
by: ryrocks | last post by:
Hi, Im making a 'contact us' page. The user click on the div, this then reveals another larger div displaying more information giving the effect of the box expanding or dropping down. I have 3...
2
by: samz | last post by:
Hello, 1. How to get my DIV (DIV.Box) fit its content (an image)? width:auto doesn't work? 2. How to get links (A) in this DIV click-able (on the IMG) in IE6 too? Thanks URL:...
1
rahulephp
by: rahulephp | last post by:
CSS Tabs - contents of a div disappear in IE & onclick is not working Here is the code: Swaps the "active" tab and "inactive" tab and swaps out the new content via the display style attribute: ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.