SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Div and ID .. How to alert content of Div ?!

    hi ..

    let`s say i have this :

    PHP Code:
    <div ID=foo>
    balalahahal 
    kalala
    </div
    how can i alert this div conetent ??
    this didn`t work :
    PHP Code:
    <script>
    alert(document.foo.value);
    </script> 
    how then ?!

  2. #2
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    found it .. getelemetbyid("foo")

  3. #3
    SitePoint Addict -TheDarkEye-'s Avatar
    Join Date
    Mar 2001
    Location
    canada
    Posts
    286
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    how about this?

    alert(document.getElementsById('foo').innerHTML);

  4. #4
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    alert(document.getElementsById('foo').innerHTML);
    alert(document.getElementsById('foo').innerTEXT);
    alert(document.getElementsById('foo').outerHTML);
    alert(document.getElementsById('foo').outerTEXT);

    this might help

  5. #5
    SitePoint Guru Richi's Avatar
    Join Date
    Jul 2001
    Location
    Hu,Bp.
    Posts
    842
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it`s work fine with alert(document.getElementsById('foo').innerHTML);

    but what the diffrence between those :
    alert(document.getElementsById('foo').innerHTML);
    alert(document.getElementsById('foo').innerTEXT);
    alert(document.getElementsById('foo').outerHTML);
    alert(document.getElementsById('foo').outerTEXT);


  6. #6
    What? Maelstrom's Avatar
    Join Date
    Oct 2001
    Location
    Whistler BC originally from Guelph Ontario
    Posts
    2,175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alert them all and see

    <div id="foo">
    <p>This is foo</p>

    </div>

    this is bar

    <a href="javascript:void(0)" onclick="alert(document.getElementById('foo').innerHTML)">innerHTML</a>
    <a href="javascript:void(0)" onclick="alert(document.getElementById('foo').innerText)">innerTEXT</a>
    <a href="javascript:void(0)" onclick="alert(document.getElementById('foo').outerHTML)">outerHTML</a>
    <a href="javascript:void(0)" onclick="alert(document.getElementById('foo').outerText)">outerTEXT</a>


    BTW it is getElementById() not getElementsById()

    Maelstrom Personal - Apparition Visions
    Development - PhP || Mysql || Zend || Devshed
    Unix - FreeBSD || FreeBsdForums || Man Pages
    They made me a sitepoint Mentor - Feel free to PM me or Email me and I will see if I can help.

  7. #7
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I really must get used to not copying and pasting other peoples code here.

    I guess it was better than getelemetbyid("foo") lol.
    Although I do get confused with

    getElementsByTagName('')


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
  •