473,386 Members | 1,785 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,386 software developers and data experts.

Change <div>

I would like to know how I loop through a html file and validate it is the
type of element I am seeking and then change something in the element.

IE

for(x=0;x<this.document.elements.length;x++)
{
if(this.element.type= = "<DIV>")
{
this.element.z-index=1;
}
}

sort of like a deck of cards, take the top one off and put it in the deck
then there is a new top card and the one placed in the deck has a new
z-index:.

Thanks
Apr 14 '06 #1
7 4587
Try this:

var divs = document.getElementsByTagName("div");

for (var i =0; i < divs.length; i++)
divs[i].style.zIndex = i;

if you need to get all the divs "under" a certain parent (container)
you could do this instead:

var divs = container.getElementsByTagName("div");

Apr 14 '06 #2

This does not seem to work do you know what I am doing wrong?

http://www.wyght.com/warren/layers.html

that is the URL

--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW

<oz*********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Try this:

var divs = document.getElementsByTagName("div");

for (var i =0; i < divs.length; i++)
divs[i].style.zIndex = i;

if you need to get all the divs "under" a certain parent (container)
you could do this instead:

var divs = container.getElementsByTagName("div");

Apr 14 '06 #3
<oz*********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Try this:

var divs = document.getElementsByTagName("div");

for (var i =0; i < divs.length; i++)
divs[i].style.zIndex = i;

if you need to get all the divs "under" a certain parent (container)
you could do this instead:

var divs = container.getElementsByTagName("div");


I got it working on IE but not on Modzilla here is the URL

http://www.wyght.com/warren/layers.html

Why does this work on IE but not Modzilla nor on NN?

--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW
Apr 14 '06 #4
News wrote on 14 apr 2006 in comp.lang.javascript:
<oz*********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Try this:

var divs = document.getElementsByTagName("div");

for (var i =0; i < divs.length; i++)
divs[i].style.zIndex = i;

if you need to get all the divs "under" a certain parent (container)
you could do this instead:

var divs = container.getElementsByTagName("div");

This does not seem to work do you know what I am doing wrong?

http://www.wyght.com/warren/layers.html

that is the URL
[please do not toppost on usenet]
divs[x].style.id="hidden"


There is no style called id.

If you ment divs[x].id,
you are not allowed to name two items the same id name.

Do not use <form> where a <div> is needed.

A for loop implementing what you want timeout-ed is not usefull.

I suppose you ment to use style.display, but visibility.hidden works in the
same way, while preserving the "place".

try this:

================ test.html ===================

<style>
..a {display:none;}
</style>

<script type="text/javascript">

var x=0;
function myDiv() {
var top=0;
var you = document.getElementById('you'); // necessary for non-ie
var divs = you.getElementsByTagName("div");
if (x>0) divs[x-1].style.display="none";
divs[x++].style.display="block";
if (x<divs.length) setTimeout("myDiv();",300);
}

</script>

<body onload='myDiv()'>

<div id="you">
<div class="a">1</div>
<div class="a">2</div>
<div class="a">3</div>
<div class="a">4</div>
<div class="a">5</div>
<div class="a">6</div>
<div class="a">7</div>
<div class="a">8</div>
<div class="a">9</div>
<div class="a">10</div>
</div>

====================================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Apr 14 '06 #5
News wrote:
<oz*********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Try this:

var divs = document.getElementsByTagName("div");

for (var i =0; i < divs.length; i++)
divs[i].style.zIndex = i;

if you need to get all the divs "under" a certain parent (container)
you could do this instead:

var divs = container.getElementsByTagName("div");

I got it working on IE but not on Modzilla here is the URL

http://www.wyght.com/warren/layers.html

Why does this work on IE but not Modzilla nor on NN?


Because you have:

function myDiv()
{
var top=0;
var divs = you.getElementsByTagName("div");
--------------^^^

Where 'you' is the id of the div. IE adds ids and names as global
variables that refer to the related DOM object, other browsers may mimic IE
in some circumstances[1], but not here. For them, 'you' is undefined, an
error is thrown and that's as far as the script goes.

It seems that what you want to do is make the n + 1 div visible each time.
So loop through until you find the visible one, make it hidden, then set
the next (or zero-th if at last div) to visible.

The rest of your script has so many errors that it surprising that it works
at all. Try:

<script type="text/javascript">
function myDiv()
{
// Declare variables
var you = document.getElementById('you');
var divs = you.getElementsByTagName("div");
var numDivs = divs.length;
var x=0;

// Look for first non-hidden div
while (divs[x].style.visibility == 'hidden'){
++x;
}

// Set it to hidden
divs[x].style.visibility = 'hidden';

// Set the next or zero-th to visible
divs[++x % numDivs].style.visibility = 'visible';

// Set the timeout
setTimeout("myDiv();",100);
}
You need to add feature detection and replace the form element with a div.
1. This IE-ism was so pervasive that other browsers felt impelled to
implement IE's proprietary behaviour because of the number of issues it
caused. However, it is only supported in Gecko browsers where the DOCTYPE
is not strict or XHTML.
--
Rob
Apr 15 '06 #6
"RobG" <rg***@iinet.net.au> wrote in message
news:44***********************@per-qv1-newsreader-01.iinet.net.au...
News wrote:
<oz*********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Try this:

var divs = document.getElementsByTagName("div");

for (var i =0; i < divs.length; i++)
divs[i].style.zIndex = i;

if you need to get all the divs "under" a certain parent (container)
you could do this instead:

var divs = container.getElementsByTagName("div");

I got it working on IE but not on Modzilla here is the URL

http://www.wyght.com/warren/layers.html

Why does this work on IE but not Modzilla nor on NN?


Because you have:

function myDiv()
{
var top=0;
var divs = you.getElementsByTagName("div");
--------------^^^

Where 'you' is the id of the div. IE adds ids and names as global
variables that refer to the related DOM object, other browsers may mimic
IE in some circumstances[1], but not here. For them, 'you' is undefined,
an error is thrown and that's as far as the script goes.

It seems that what you want to do is make the n + 1 div visible each time.
So loop through until you find the visible one, make it hidden, then set
the next (or zero-th if at last div) to visible.

The rest of your script has so many errors that it surprising that it
works at all. Try:

<script type="text/javascript">
function myDiv()
{
// Declare variables
var you = document.getElementById('you');
var divs = you.getElementsByTagName("div");
var numDivs = divs.length;
var x=0;

// Look for first non-hidden div
while (divs[x].style.visibility == 'hidden'){
++x;
}

// Set it to hidden
divs[x].style.visibility = 'hidden';

// Set the next or zero-th to visible
divs[++x % numDivs].style.visibility = 'visible';

// Set the timeout
setTimeout("myDiv();",100);
}

You need to add feature detection and replace the form element with a div.
1. This IE-ism was so pervasive that other browsers felt impelled to
implement IE's proprietary behaviour because of the number of issues it
caused. However, it is only supported in Gecko browsers where the DOCTYPE
is not strict or XHTML.
--
Rob


It works thanks and thanks for explaining what I was doing wrong

--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW
Apr 17 '06 #7

"Evertjan." <ex**************@interxnl.net> wrote in message
news:Xn*******************@194.109.133.242...
News wrote on 14 apr 2006 in comp.lang.javascript:
<oz*********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
Try this:

var divs = document.getElementsByTagName("div");

for (var i =0; i < divs.length; i++)
divs[i].style.zIndex = i;

if you need to get all the divs "under" a certain parent (container)
you could do this instead:

var divs = container.getElementsByTagName("div");

This does not seem to work do you know what I am doing wrong?

http://www.wyght.com/warren/layers.html

that is the URL


[please do not toppost on usenet]
divs[x].style.id="hidden"


There is no style called id.

If you ment divs[x].id,
you are not allowed to name two items the same id name.

Do not use <form> where a <div> is needed.

A for loop implementing what you want timeout-ed is not usefull.

I suppose you ment to use style.display, but visibility.hidden works in
the
same way, while preserving the "place".

try this:

================ test.html ===================

<style>
.a {display:none;}
</style>

<script type="text/javascript">

var x=0;
function myDiv() {
var top=0;
var you = document.getElementById('you'); // necessary for non-ie
var divs = you.getElementsByTagName("div");
if (x>0) divs[x-1].style.display="none";
divs[x++].style.display="block";
if (x<divs.length) setTimeout("myDiv();",300);
}

</script>

<body onload='myDiv()'>

<div id="you">
<div class="a">1</div>
<div class="a">2</div>
<div class="a">3</div>
<div class="a">4</div>
<div class="a">5</div>
<div class="a">6</div>
<div class="a">7</div>
<div class="a">8</div>
<div class="a">9</div>
<div class="a">10</div>
</div>

====================================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


It is working now thanks for your help

--

Totus possum, totum Deum.
Totus ero, totum meum.
WSW
Apr 17 '06 #8

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

Similar topics

13
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
1
by: Philo | last post by:
How do I select all <div> tags except those which contain a <table> tag somewhere within them? Example XML: <********************** sample input ***********************> <txtSectionBody>...
3
by: Paul Thompson | last post by:
When I put a <div ...> inside a <table> specification, functionality is not there. When I put the <table> inside the <div> everything works. Why is that?
3
by: Catherine Lynn Smith | last post by:
I am creating a webpage with dhtml <DIV> layers and I want a link on one layer to modify the content on another but I seem to keep running into errors. Basically I create a layer in the middle...
8
by: Daniel Hansen | last post by:
I know this must seem totally basic and stupid, but I cannot find any reference that describes how to control the spacing between <p>...</p> and <div>...</div> blocks. When I implement these on a...
3
by: Josef K. | last post by:
Asp.net generates the following html when producing RadioButton lists: <td><input id="RadioButtonList_3" type="radio" name="MyRadioButtonList" value="644"...
28
by: Kent Feiler | last post by:
1. Here's some html from a W3C recommendations page. <P>aaaaaaaaa<DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</DIV> 2.Although I didn't think it would make any difference, I tried it with the...
5
by: Agix | last post by:
Hi there, Please check out : http://clarifysolutions.co.uk/certenroll/ The source is included below. This page is a test, so I can play about with paddings, margins and layouts using divs as...
8
prino
by: prino | last post by:
Hi all, I've written code (in REXX) that takes files in legacy languages (PL/I, COBOL, z/OS assembler, etc) and converts them into HTML in a format similar to what's displayed in the z/OS ISPF...
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: 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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.