SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist ashattuc's Avatar
    Join Date
    Aug 2002
    Location
    Boise, Idaho
    Posts
    411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with innerHTML

    I'm trying to grab the following value from .innerhtml:

    <img src="myimage.gif" />

    But it grabs it without the ending backslash and space, as in the following:

    <img src="myimage.gif">

    In order for the function I'm working on to work properly, it needs to grab the exact HTML that's in there. Is there some way to do this?

    Thanks!
    Chris
    Chris S.

    Free Web Scripts - Form generators, AJAX tools and more!
    Micro CMS - A totally free AJAX-based, SEO-ed CMS!

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,800
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Browsers convert the (X)HTML that you code into the particular variant that they expect to use when they display your page. That means that XHTML pages served as HTML will have the closing / removed from the copy of the page before it displays and it will therefore not be there when the innerHTML references it.

    To retain the / you need to serve the page as XHTML and not as HTML (of course that will only work with those browsers that understand web pages served that way - which does not include Internet Explorer which cannot handle XHTML served correctly).
    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="^$">


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
  •