SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2010
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using document.writeln()

    I'm sorry if this question seem very basic but I just start learning javascript.
    I would like to display an image but not sure why it is not working. In a nutshell, here's my code

    Code:
    <html>
    <head></head>
    <body>
    
    <script type="text/javascript">
    document.writeln("<img src=/"xMark.jpg /" width=25 height=25 >");
    </script>
    
    </body>
    </html>

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,607
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Does the filename really have a space on the end after the .jpg? If not then removing that space from your code might help.

    Also replacing the two / with \ so as to properly escape the " will also help or alternatively just get rid of them completely and surround the whole string with ' instead of " so that they don't need to be escaped.
    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 Enthusiast
    Join Date
    Mar 2010
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried single quote like you suggested and it works great.

    document.writeln('<img src="xMark.jpg" width="20" height="20">');

    thank you


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
  •