/    Sign up×
Community /Pin to ProfileBookmark

Javascript working in IE not in firefox

I’m trying to code a tree-list using javascript, and the following doesn’t seem to be working in firefox, but works fine in IE

//javascript function executed onload

[code]
function tree_init(){

varTree = document.getElementById(“tree”)
varState = varTree.getElementsByTagName(“li”);

for(i=0;i<varState.length;i++){
varCity = varState.item(i).getElementsByTagName(“ul”);
if(varCity.length > 0) {
varState.item(i).style.listStyleType = ‘disc’;
}
else varState.item(i).style.listStyleType = ‘square’;
}

}

//html

<div id=”tree”>
<ul>
<li>Texas</li>
<ul>
<li>Sonora</li>
<ul>
<li>abc1</li>
<li>abc2</li>
<li>abc3</li>
</ul>
<li>Sanderson</li>
<li>Alpine</li>
</ul>
</ul>
</div>
[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991May 20.2008 — Try this:[code=php]varCity = varState[i].getElementsByTagName("ul");
if(varCity.length > 0) {
varState[i].style.listStyleType = 'disc';
}
else varState[i].style.listStyleType = 'square';[/code]
to replace the similar lines in your version.
Copy linkTweet thisAlerts:
@KorMay 20.2008 — You have wrong nested the lists. Mozilla is right. You have no [B]ul [/B]elements nested inside the [B]li[/B] elements, thus varCity.length is always 0. Should have been, probably:
<i>
</i>&lt;div id="tree"&gt;
&lt;ul&gt;
[COLOR="Blue"]&lt;li&gt;[/COLOR]Texas
&lt;ul&gt;
[COLOR="DarkGreen"]&lt;li&gt;[/COLOR]Sonora
&lt;ul&gt;
&lt;li&gt;abc1&lt;/li&gt;
&lt;li&gt;abc2&lt;/li&gt;
&lt;li&gt;abc3&lt;/li&gt;
&lt;/ul&gt;
[COLOR="DarkGreen"]&lt;/li&gt;[/COLOR]
&lt;li&gt;Sanderson&lt;/li&gt;
&lt;li&gt;Alpine&lt;/li&gt;
&lt;/ul&gt;
[COLOR="Blue"]&lt;/li&gt;[/COLOR]
&lt;/ul&gt;
×

Success!

Help @vpraveen84 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...