add innerHTML div by javacript
-
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 ??
-
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 ??
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.
-
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.