Reputation: 3621
This was just a query in another of my questions. However i got no solution so i am reposting this question and hopefully someone can solve my dilemma.
I have a div.I want the div contents to be editabe. what i basically want is onlick of a button the div should turn into a text box and allow the user to change the contents of the div. I would prefer to avoid Jquery.
HTML
<div id="main">
<div id="allowedit">CLICK BUTTON TO EDIT THIS TEXT
<input type="button" value="CLK ME" onclick="changetext(this)" />
</div>
<div>
JAVASCRIPT
changetext = function (e) {
src=(e.parentNode);
src.outerHTML="<div><input +"+"name=input"+"></div>";
}
Upvotes: 6
Views: 4609
Reputation: 4225
<div id="allowedit" contenteditable="true">
CLICK BUTTON TO EDIT THIS TEXT
</div>
Upvotes: 1
Reputation: 26930
You can use html attribute contenteditable
<div contenteditable="true">
This text can be edited by the user.
</div>
Upvotes: 12