Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
span children management: not working in firefox
Old 04-04-2010, 03:19 PM span children management: not working in firefox
Junior Talker

Posts: 3
Trades: 0
Hi,

I have a span, and in that I have many DIVs.
I want to enable one div at a time, on user click.

for this, i have written a JS function that changes display option for the divs.

the code is :

Code:
function enableGallery(name)
{
     var children=document.getElementById('gallery').childNodes;

         for (var i=0;i<children.length;i++)
         {
             elem = children[i];

             if (elem != null)
             {
                     elem.style.display='none';
             }
             else
             {
                     alert('elem is null');
             }
         }

         var my=document.getElementById(name);
         my.style.display='block';
}
my span looks like


Code:
                <span id="gallery" style="display:none;background-color: black; height: 100%; color: white; padding: 10px;">
                    <div id="simplegallery1" name = "simplegallery1"  style="display:none;background-color: black;"> </div>
<div id="simplegallery2" name = "simplegallery2"  style="display:none;background-color: black;"> </div>
<div id="simplegallery3" name = "simplegallery3"  style="display:none;background-color: black;"> </div>
                </span>
the JS function works well in IE, but in FF, it says it has 7 children elements, but then iterates only one time.

Any suggestion how to write this function in a browser independent manner?

Thanks in anticipation
Saurabh
<link drop removed>

Last edited by chrishirst; 04-04-2010 at 04:30 PM..
qtriangle is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 04-04-2010, 04:29 PM Re: span children management: not working in firefox
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
a div is a block element and as such should NOT be inside an inline element such as a span.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-05-2010, 12:26 AM Re: span children management: not working in firefox
Junior Talker

Posts: 3
Trades: 0
Does it mean replacing all DIV with SPAN will solve my problem?
__________________
Qtriangle Infotech

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
qtriangle is offline
Reply With Quote
View Public Profile
 
Old 04-05-2010, 06:28 AM Re: span children management: not working in firefox
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Should do, AND use the getElementsByTagName method insted of childNodes() as childNodes will return the text elements as "nodes"
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-05-2010, 10:32 AM Re: span children management: not working in firefox
Junior Talker

Posts: 3
Trades: 0
Thanks, your tip was great. It indeed was giving me the text element.

It meant I had to use getElementbyId("<spanid>").getElementsbyTagName("d iv").

But it returned me a whole bunch of divs from whole page, not from the span container.

I thought getElementbyId.getElementsbyTagName should give me elements matching the tag name, and contained within the output of getElementbyId.

But it seems it just adds the output of both functions, and placing a dot between the two does not mean output of first would act as input of the next one.

This was weird for me. Anyways I have got it working, using absolute getElementbyId for all divs contained in the span.

Thanks for your good tip though.
__________________
Qtriangle Infotech

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
qtriangle is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to span children management: not working in firefox
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.63632 seconds with 12 queries