SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    world
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up error:childNodes.0 is null or not a object

    Hi,
    The following script shows text(in a fixed position ie.class="yui-g") when mouse pointer over a image .
    This works fine in firefox but shows error in IE and it opera it doesnot
    show text !

    Error: childNodes.0 is null or not a object .

    Code JavaScript:
    function shtext(s)
    {
     
    	var proj=document.getElementById("CaptionName");
     
    	proj.childNodes[0].nodeValue=s;
     
    }
     
    function removetext()
    {
    	var proj=document.getElementById("CaptionName");
     
    	proj.childNodes[0].nodeValue="\r";
     
    }

    Code HTML4Strict:
    <A onMouseOver="shtext('title 1');"  onmouseout=removetext('');></a>

    Code CSS:
    <div class="yui-g" id=CaptionName >

    Hope it is clear .How to fix it ?

    Thanks.

  2. #2
    SitePoint Wizard gRoberts's Avatar
    Join Date
    Oct 2004
    Location
    Birtley, UK
    Posts
    2,439
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why don't you just use:

    Code javascript:
    function shtext(s)
    {
        var proj=document.getElementById("CaptionName");
        proj.innerHTML = s;
    }
     
    function removetext()
    {
        var proj=document.getElementById("CaptionName");
        proj.innerHTML = '';
    }

    or

    Code javascript:
    function shtext(s)
    {
        var proj=document.getElementById("CaptionName");
        while(proj.childNodes.length > 0)
        proj.removeChild(proj.firstChild);
        proj.appendChild(document.createTextNode(s));
    }
     
    function removetext()
    {
        var proj=document.getElementById("CaptionName");
        while(proj.childNodes.length > 0)
        proj.removeChild(proj.firstChild);
    }


  3. #3
    SitePoint Guru SSJ's Avatar
    Join Date
    Jan 2007
    Posts
    828
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by gRoberts View Post
    Why don't you just use:

    Code javascript:
    function shtext(s)
    {
        var proj=document.getElementById("CaptionName");
        proj.innerHTML = s;
    }
     
    function removetext()
    {
        var proj=document.getElementById("CaptionName");
        proj.innerHTML = '';
    }

    or

    Code javascript:
    function shtext(s)
    {
        var proj=document.getElementById("CaptionName");
        while(proj.childNodes.length > 0)
        proj.removeChild(proj.firstChild);
        proj.appendChild(document.createTextNode(s));
    }
     
    function removetext()
    {
        var proj=document.getElementById("CaptionName");
        while(proj.childNodes.length > 0)
        proj.removeChild(proj.firstChild);
    }
    Yes definitely. This is a preferred way to work with. I also suggest you this solution and it will work better

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2004
    Location
    world
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    thanks a lot buddy you save my time .


Bookmarks

Posting Permissions

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