SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Works in IE7, But not in Firefox

    Hello,
    i have a url like this

    Code:
    </td><a href="#" onclick="spanmap()"><span id="spanmap">Expand  +</span></a></td>
    Now i am manipulating the text inside the <span> and change the text when user clicks.

    PHP Code:
        function spanmap() {
          var 
    control document.getElementById("spanmap");
                   
    alert(control.innerText);
           if (
    control.innerText=="Expand +"){
              
    control.innerText="Collapse -";
           }else if (
    control.innerText=="Collapse -"){
             
    control.innerText="Expand +";
                   }else{
                   }        
               } 
    Just works fine in IE7,
    But in firefox, did not work, the alert displays 'Undefined' in FireFox. but ie7 display the inner text correctly.

    Please help

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,597
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    There is no such thing as innerText - try using innerHTML instead.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    oh, is it felgall,
    ill try your suggessions,
    thank you.

  4. #4
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Yes, if i change it to control.innerHTML, Fire fox says 'Undefined'.
    but no message appear if i put innerText. why it is says Undefined ?

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    With innerHTML, it doesn't match because the HTML has two spaces between the Expand and the +. Have the HTML match what the script expects, and it wil go fine.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Have the HTML match what the script expects, and it wil go fine.
    pmw57, i did not get what you sad,

  7. #7
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    960
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    InnerHtml just Works fine !!!
    i just put an spell mistake

    Thank You every one !!!


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
  •