I’m making a short simple html quiz with the help of some javascript. The problem is I don’t want to use <input> to accept the answers and I’m looking for an alternative. The javascript runs the input against the tags ID. Would it be possible to use another tag with contenteditable. I want the box to say “type answer here”. If the javascript checks ID1, could I have something like,
<p id="id1" contenteditable="true">Type answer here</p>
Instead of
<input type="text" id="id1">
It seems ok in theory but when I test it it’s like it’s not running what I typed in against the javascript. Any suggestions?
Update: I’m guessing it’s not working because perhaps contenteditable doesn’t actually change the text in the tag. Any alternatives / workarounds to the tag. Thanks 🙂
Non-form elements don’t have a
valueproperty in JavaScript. You’ll have to use eitherinnerHTMLortextContent(depending on whether you want to preserve HTML tags or not) to get the value.↪ View an example at JSFiddle