Daniel Alsaker Daniel Alsaker - 2 months ago 7
HTML Question

How to write content within tags of a html element JavaScript

So I am thinking something similar to how you in php can just run a function within a html element and that way get it to echo something in the html element.
Is there a way to choose a specific place for javascript to write with for example .innerHTML or .createTextNode?

What I wanna do is to add contenteditable="true" within a html element onclick of another button.

The reason I wanna do this is because I have a paragraph that should become editable only after onclick of a button.

I apologize that I haven't put in any code for an example, but I don't really think that is needed, as it would only be a paragraph and a button, as I don't know how the javascript should be written.

Answer

With a simple js onclick event you can do this

onclick="document.getElementById('p').setAttribute('contenteditable', true);"

here's a fiddle for this.

Comments