2

Possible Duplicate:
'innerText' works in IE, but not in Firefox

Why the following script work on IE and safari but not in Firefox?

<html>

<head><script type="text/javascript">

function ShowHide(strTag ,strAttribute){

var elem = document.getElementsByTagName(strTag); 
var elem1 = evt.srcElement || evt.target; 

for (var i=0;i<elem1.children.length;i++){ 
    elem1.children[i].innerText=="4" ? elem1.children

[i].innerText="6":elem1.children[i].innerText="4"; 
} 
    for (var i =0;i<elem.length;i++) { 
        if(elem[i].getAttribute(strAttribute)=="yes") { 
         elem[i].style.display=='none'? elem[i].style.display='block':elem

[i].style.display='none'; 
         } 
     } 
} 

</script>


<div id=div1 onclick="ShowHide('div','exp2');">
<font face=Webdings color=BLACK>4</font> click here for some expandable 

divs...</div> 
<div id=div2 exp2='yes' style="display:none;">I'm a div!</div> 
<div id=div3 exp2='yes' style="display:none;">More of them divs...</div> 
<div id=div4 exp2='yes' style="display:none;">Me too! divs...</div> 

</body>
</html>
Community
  • 1
  • 1
NewB
  • 31
  • 1
  • What? Try repasting with some formatting. The little block of binary is there to help you with code formatting, please use it. – josh.trow Nov 05 '10 at 20:23

4 Answers4

7

The innerText property does not work on Firefox, that property is IE-specific (although IIRC is supported by Opera/Chrome).

Firefox uses the W3C standard Node::textContent property.

Christian C. Salvadó
  • 807,428
  • 183
  • 922
  • 838
3
  1. I don't see where "evt" comes from, but event objects are referenced differently in Firefox and IE
  2. Firefox does not have an "innerText" attribute for manipulation

(That "evt" thing makes me wonder how this works even in IE.)

Pointy
  • 405,095
  • 59
  • 585
  • 614
1

CMS is right but also incomplete.

var elem1 = evt.srcElement || evt.target; 

This line fails because 'evt is not defined'

josh.trow
  • 4,861
  • 20
  • 31
1

evt is undefined

Unless you're passing in the event object from the onclick handler somewhere not included in your snippet Firefox has no idea what evt is. If you want to find the target in this manner, pass it in as a parameter to the function.

Anthony Corbelli
  • 877
  • 4
  • 10