php - Javascript copy & symbol from div to input malfunction -
i cannot find answer question...
the problem. javascript copying text div input (textbox), fails copy & &, , copies &. see code plus example.
i have following code (on different pages, simplify put here):
input want text copied.
<input name="artist" id="txtartist" type="text" placeholder="introduce artist" /> div text copied from. data populated sql database.
<div id="art0"><div onclick="copytext(0)">mumford & sons</div></div>' the function fails...
function copytext(rowid){ var content = document.getelementbyid('art'+rowid).innerhtml.replace(/<\/?[^>]+(>|$)/g, "\n"); document.getelementbyid("txtartist").value = document.getelementbyid('art'+rowid).innerhtml; document.getelementbyid("txtartist").value = content; } expected result inside textbox: mumford & sons
actual result inside textbox: mumford & sons
any please?
thank all!!
use .textcontent instead of .innerhtml:
var content = document.getelementbyid('art'+rowid).textcontent; note .textcontent not supported ie 8 , lower, if unfortunate, test , use .innertext instead.
var prop = 'textcontent' in document.body ? 'textcontent' : 'innertext', content = document.getelementbyid('art'+rowid)[prop];
Comments
Post a Comment