Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. add innerHTML div by javacript

add innerHTML div by javacript

Scheduled Pinned Locked Moved Web Development
helpjavascripthtmlquestion
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AnhTin
    wrote on last edited by
    #1

    hi all I have some code but have problem when add "html" to tag div by javacript <!-- function addEvent() { var strHTML = '<a href="javascript:posttreeview('39,28', '4');">demo</a>'; document.getElementById('myDiv').innerHTML = strHTML; } //-->

    [Add Some Elements](javascript:addEvent();)

    But it error javacipt when click to text?? I think it error in href="javascript:posttreeview('39,28', '4');" Some body help me ??

    N 1 Reply Last reply
    0
    • A AnhTin

      hi all I have some code but have problem when add "html" to tag div by javacript <!-- function addEvent() { var strHTML = '<a href="javascript:posttreeview('39,28', '4');">demo</a>'; document.getElementById('myDiv').innerHTML = strHTML; } //-->

      [Add Some Elements](javascript:addEvent();)

      But it error javacipt when click to text?? I think it error in href="javascript:posttreeview('39,28', '4');" Some body help me ??

      N Offline
      N Offline
      newc1
      wrote on last edited by
      #2

      Hi, Your problems are being caused by the use of multiple ' and " characters within your strHTML variable. var strHTML = '<a href="javascript:posttreeview('39,28', '4');">demo</a>'; The second ' within this line is interpreted as the end of the string i.e. '<a href="javascript:posttreeview(' and will therfore cause errors when attempting to process the remaining script. To correct this issue you will simply need to break up the string as follows: var strScript = "javascript:posttreevie('39,28', '4');"; var strHTML = '<a href="' + strScript + '">demo</a>'; Hope this helps.

      Clean code is the key to happiness.

      J 1 Reply Last reply
      0
      • N newc1

        Hi, Your problems are being caused by the use of multiple ' and " characters within your strHTML variable. var strHTML = '<a href="javascript:posttreeview('39,28', '4');">demo</a>'; The second ' within this line is interpreted as the end of the string i.e. '<a href="javascript:posttreeview(' and will therfore cause errors when attempting to process the remaining script. To correct this issue you will simply need to break up the string as follows: var strScript = "javascript:posttreevie('39,28', '4');"; var strHTML = '<a href="' + strScript + '">demo</a>'; Hope this helps.

        Clean code is the key to happiness.

        J Offline
        J Offline
        Johnny
        wrote on last edited by
        #3

        Alternatively you can escape the quotes: var strHTML = '

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups