SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    document.getElementById("g_23") has no properties

    I have defined a div so:
    <div id='g_23' onclick='alert(document.getElementById("g_23").innerHTML);'>ciao</div>

    but the javascript console when i click on div tell me:
    document.getElementById("g_23") has no properties

    Whiy?
    How i can do?
    thanks

  2. #2
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uhh.. It works for me, but I recommended you to use this instead.

    Code:
    <div id='g_23' onclick='alert(this.innerHTML);'>ciao</div>

  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    62
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did so:
    <div id='g_23' onclick='id=0;this.bgColor="#55FF55";'>ciao</div>

    But if i click on the div, the background not change.
    Why?
    Thanks for reply

  4. #4
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this.style.backgroundColor is the correct syntax, and the id=0 doesn't make much sense.

  5. #5
    SitePoint Zealot the DtTvB's Avatar
    Join Date
    Jul 2006
    Location
    Thailand
    Posts
    162
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by romaluca View Post
    I did so:
    <div id='g_23' onclick='id=0;this.bgColor="#55FF55";'>ciao</div>

    But if i click on the div, the background not change.
    Why?
    Thanks for reply
    bgColor is for body, and some table elements, not for div!
    You should use this.style.background or this.style.backgroundColor instead!


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
  •