www.webdeveloper.com
Results 1 to 15 of 15

Thread: childNodes not working in firefox i have code

  1. #1
    Join Date
    Mar 2011
    Posts
    12

    childNodes not working in firefox i have code

    anybody help this code to working in chrome or firefox
    Code:
     <script type="text/javascript">  function hideAll()   {   try   {    document.getElementById("xToolbar").childNodes[0].childNodes[0].childNodes[1].childNodes[2].childNodes[2].style.display = `none`;     document.getElementById("xToolbar").childNodes[0].childNodes[0].childNodes[1].childNodes[2].childNodes[0].style.display = `none`;     document.getElementById("xToolbar").childNodes[0].childNodes[0].style.width=`280px`;    }    catch(err)         {         }} 
       </script>

  2. #2
    Join Date
    Mar 2011
    Posts
    12
    this code not work in firefox javascritp

    document.getElementById("xToolbar").childNodes[0].childNodes[0].childNodes[1].childNodes[2].childNodes[2].style.display = `none`;

  3. #3
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Browsers count in different ways the childNodes. FF counts all the possible textNodes (the "gaps") as childNodes, while IE counts only some of them.

    Don't use childNodes. use rather getElementsByTagName(). Or check for the nodeName. Or nodeType.

    But first: what element is
    .childNodes[0].childNodes[0].childNodes[1].childNodes[2].childNodes[2]
    ?

    Can you post the HTML structure as well?

  4. #4
    Join Date
    Mar 2011
    Posts
    12
    but this code is not working in firfox
    document.getElementById("xToolbar").getElementsByTagName("div")[0].getElementsByTagName("div")[0].getElementsByTagName("div")[1].getElementsByTagName("div")[2].getElementsByTagName("div")[0].style.display = 'none';


    very good is working in firfox
    document.getElementById("xToolbar").getElementsByTagName("div")[0].getElementsByTagName("div")[0].style.width='280px';


    please kor replay to me

  5. #5
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428

  6. #6
    Join Date
    Mar 2011
    Posts
    12
    look attachment mr kor
    Attached Images Attached Images

  7. #7
    Join Date
    Mar 2011
    Posts
    12
    after look the picture i need display none this div

  8. #8
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    have you considered using getElementsByClassName() instead? Should work in all the browsers, except IE7 and IE8, but here's a workaround:

    Code:
    function setClassMethod(){
    if (!document.getElementsByClassName) {
    	document.getElementsByClassName = function (cn) { 
    		var rx = new RegExp("(?:^|\\s)" + cn+ "(?:$|\\s)");
    		var allT = document.getElementsByTagName("*"), allCN = [], ac="", i = 0, a;
    			while (a = allT[i=i+1]) {
    			  ac=a.className;
    			  if ( ac && ac.indexOf(cn) !==-1) {
    				if(ac===cn){ allCN[allCN.length] = a; continue;   }
    				rx.test(ac) ? (allCN[allCN.length] = a) : 0;
    			  }
    			}
    		return allCN;
    	}
    }
    }
    Just call this function onload, as well.

  9. #9
    Join Date
    Mar 2011
    Posts
    12
    function hideAll()
    {
    //is working internet explorer and firefox
    document.getElementById("wibiyaToolbar").getElementsByTagName("div")[0].getElementsByTagName("div")[0].style.width='280px';

    //this is working only internet explorer but not firefox
    document.getElementById("wibiyaToolbar").childNodes[0].childNodes[0].childNodes[1].childNodes[2].childNodes[2].style.display = 'none';
    document.getElementById("wibiyaToolbar").childNodes[0].childNodes[0].childNodes[1].childNodes[2].childNodes[0].style.display = 'none';

    }

  10. #10
    Join Date
    Mar 2011
    Posts
    12
    mr kor
    you code it's not working to me and too hard to understand

  11. #11
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by drhow View Post
    function hideAll()
    {
    //is working internet explorer and firefox
    document.getElementById("wibiyaToolbar").getElementsByTagName("div")[0].getElementsByTagName("div")[0].style.width='280px';

    }
    OK, so? It works? It works. What else do you want?

  12. #12
    Join Date
    Mar 2011
    Posts
    12
    document.getElementById("wibiyaToolbar").childNodes[0].childNodes[0].childNodes[1].childNodes[2].childNodes[2].style.display = 'none';
    document.getElementById("wibiyaToolbar").childNodes[0].childNodes[0].childNodes[1].childNodes[2].childNodes[0].style.display = 'none';


    i want these code working in firefox but it's working ie

    try this my web site on ie and firefox
    http://‬www.myaspnet.com

    drhow

  13. #13
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    Quote Originally Posted by drhow View Post
    document.getElementById("wibiyaToolbar").childNodes[0].childNodes[0].childNodes[1].childNodes[2].childNodes[2].style.display = 'none';
    document.getElementById("wibiyaToolbar").childNodes[0].childNodes[0].childNodes[1].childNodes[2].childNodes[0].style.display = 'none';


    i want these code working in firefox but it's working ie

    try this my web site on ie and firefox
    http://‬www.myaspnet.com

    drhow
    I have already told you that those codes won't work in Firefox. I have already told you why. I have told you to use getElementsByTagName() or getElementsByClassName().

  14. #14
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,428
    OK, here another solution:

    Here's a "gap cleaner"
    Code:
    var notWhitespace = /\S/;
    function cleanWhitespace(node) {
      for (var x = 0; x < node.childNodes.length; x++) {
        var childNode = node.childNodes[x]
        if ((childNode.nodeType == 3)&&(!notWhitespace.test(childNode.nodeValue))) {
    // that is, if it's a whitespace text node
          node.removeChild(node.childNodes[x])
          x--
        }
        if (childNode.nodeType == 1) {
    // elements can have text child nodes of their own
          cleanWhitespace(childNode)
        }
      }
    }
    Call it onload like this (I see you call a function on body - don't)
    Code:
    onload=function(){
    cleanWhitespace(document);
    hideAll();
    }
    And remove the hideAll() onload from BODY

    Now you can use childNodes the way you like.

  15. #15
    Join Date
    Mar 2011
    Posts
    12
    asp.net library


    thank you
    Last edited by drhow; 03-23-2011 at 01:39 AM. Reason: asp.net library

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles