SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    <DIV> (or similar) on same line?

    I have the following Javascript function:

    Code:
    function replace() {
    
       document.all.text_div.innerText = 'hello jim';
    
    }
    and the following html:

    HTML Code:
    The message is: <div id='text_div'>hello fred</div>
    So basically when the function is called it should change the text in the <div>. However, I need the phrase "The message is" AND the <div> to be on the same line!!

    How can I do this? I don't mind whether I am using a <div> or not, just anything that Javascript can change on the fly. Could CSS be the answer? Or just an alternative to <div>? Or some other way of changing content with Javascript?

    Thanks so much in advance for your help,

    Shai

  2. #2
    What a twist! Kings's Avatar
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    954
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use <span> instead of <div>, or just use <div style="display:inline">
    Dennis Pallett - NoCertainty - My Personal Weblog
    The Web Network: ASPit | PHPit | WebDev-Articles
    Blogs: TalkFones | Holidayzer | PHPit Blog

  3. #3
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help! Just so you know, <span> also puts itself on a new line. The display:inline thing worked though. I knew I had used it before and just couldn't remember where/how!!

    Thanks,

    Shai

  4. #4
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, use a <span>.

    That fucntion will only work in IE.

    You should use DOM1+ methods and properties, instead of IE's proprietary document.all and innerText. innerHTML isn't part of DOM1+, but it has much better cross-browser support than innerText.

    Code:
    function replace() {
       document.getElementById('text_div').innerHTML = 'hello jim';
    }
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


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
  •