Saturday, May 11, 2024
 Popular · Latest · Hot · Upcoming
196
rated 0 times [  199] [ 3]  / answers: 1 / hits: 170535  / 12 Years ago, sat, may 12, 2012, 12:00:00

Why this does not work in firefox i try to select the category and then make subcategory visible.



<script type=text/javascript>
function show_sub(cat) {
var cat = document.getElementById(cat);
var sub = cat.getElementsByName(sub);
sub[0].style.display='inline';
}

</script>


-



<ul>
<li id=cat onclick=show_sub(this)>
Top 1
<ul style=display:none name=sub>
<li>Sub 1</li>
<li>Sub 2</li>
<li>Sub 3</li>
</ul>
</li>
<li>Top 2</li>
<li>Top 3</li>
<li>Top 4</li>
</ul>


EDIT Answer is:



<script type=text/javascript>
function show_sub(cat) {
cat.getElementsByTagName(ul)[0].style.display = (cat.getElementsByTagName(ul)[0].style.display == none) ? inline : none;
}
</script>

More From » html

 Answers
13

ULs don't have a name attribute, but you can reference the ul by tag name.



Try replacing line 3 in your script with this:



var sub = cat.getElementsByTagName(UL);

[#85621] Friday, May 11, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
stefanicarolinat

Total Points: 145
Total Questions: 91
Total Answers: 93

Location: Cambodia
Member since Thu, Oct 7, 2021
3 Years ago
stefanicarolinat questions
Mon, Nov 15, 21, 00:00, 3 Years ago
Fri, Apr 16, 21, 00:00, 3 Years ago
Thu, Oct 15, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
;