Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript not working on firefox [duplicate]

Tags:

javascript

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>
like image 259
NewB Avatar asked Sep 04 '26 05:09

NewB


2 Answers

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.

like image 172
Christian C. Salvadó Avatar answered Sep 06 '26 20:09

Christian C. Salvadó


  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.)

like image 24
Pointy Avatar answered Sep 06 '26 22:09

Pointy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!