SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    issue with innerHTML

    hi,

    i have a problem with innerHTML

    if i wrote
    document.getElementById('someid').innerHTML = "ok";
    then it wroks

    but when i wrote
    document.getElementById('someid').innerHTML = "<sometext> ok";
    it does not work.
    i.e. <sometext> is not visible

    if check on firebug / dom it display..
    <sometext> ok </sometext>

    please help..
    how do i print / display above string as it as.

    you may download file or check below link..
    please click here

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The problem is the page thinks your posting an HTML element, to avoid this you will need to convert the string so < and > for example get converted to HTMLEntities. See the following link for a quick and painless way to do this:

    http://css-tricks.com/snippets/javas...or-javascript/

  3. #3
    SitePoint Member
    Join Date
    May 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this might not work.. in above case <b> or <i> or <font> tags does not work.

  4. #4
    SitePoint Member
    Join Date
    Oct 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you want "<sometext>" to be visible, then use .innerText instead of .innerHtml


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
  •