In the following snippet everything works as expected, but when I click "Show Source" Firefox produces this error:
-- [11:07:30.630] TypeError: document.getElementbyId is not a function @ http://localhost:8888/html5/native-rich-text.html:10
And Safari produces a similar error. What is causing this?
function showSource() {_x000D_
var content = document.getElementbyId("edit").innerHTML_x000D_
content.replace(/</g, '<');_x000D_
content.replace(/>/, '>: ');_x000D_
prompt("Your Code:", content);_x000D_
_x000D_
}_x000D_
_x000D_
function createLink() {_x000D_
var url = prompt("Enter URL:", "http://");_x000D_
if (url)_x000D_
document.execCommand("createlink", false, url);_x000D_
}
_x000D_
<h1>Native Rich Text</h1>_x000D_
<p>No textboxes here, that's a <div> element!</p>_x000D_
<div>_x000D_
<input type="button" value="Bold" onclick="document.execCommand('bold', false, null);">_x000D_
<input type="button" value="Italic" onclick="document.execCommand('italic', false, null);">_x000D_
<input type="button" value="Underline" onclick="document.execCommand('underline', false, null);">_x000D_
<input type="button" value="Add Link" onclick="createLink();">_x000D_
<input type="button" value="Show Source" onclick="showSource();">_x000D_
</div>_x000D_
<div id="edit" style="border:solid black; height: 300px; width: 400px;" contenteditable="true">_x000D_
Hello!_x000D_
</div>
_x000D_
This question is related to
javascript
html
JavaScript is case-sensitive. The b
in getElementbyId
should be capitalized.
var content = document.getElementById("edit").innerHTML;
Source: Stackoverflow.com