• Archives

  • AddThis Social Bookmark Button

    Add to Technorati Favorites

  • Using get element by id

    By krates | January 17, 2008

    Get element by id is a function which will return the the content inside a element for example

    Example

    <html>

    <head>

    <script type=”text/javascript” >

    function gebid(){

    var xyz=document.getElementById(“text”);

    alert(xyz.innerHTML);

    }

    </script>

    </head>

    <body>

    <h1 id=”text” onclick=”gebid()”>You will see this same text when you will click here</h1>

    </body>

    </html>

    Thanks

    krates

    Share and Enjoy:
    • Digg
    • del.icio.us
    • Facebook
    • NewsVine
    • Reddit
    • StumbleUpon
    • YahooMyWeb
    • Google Bookmarks
    • Yahoo! Buzz
    • TwitThis
    • Live
    • LinkedIn
    • Pownce
    • MySpace

    Topics: Javascript | 4 Comments »

    Related Links:

    4 Responses to “Using get element by id”

    1. Tom Says:
      February 21st, 2008 at 9:48 am

      Nope, you won’t, it needs to be alert(xyz.innerHTML);

      -Tom

    2. krates Says:
      February 21st, 2008 at 2:24 pm

      Thanks for telling it was a silly mistake by me.

    3. Marshall Says:
      June 16th, 2008 at 6:46 am

      I have this code written down as a JS code but am prgramming in XUL not html.

    4. Marshall Says:
      June 16th, 2008 at 6:48 am

      What needs to be chnaged

    Comments

    Security Code: