AnaMaria
AnaMaria

Reputation: 3621

Allowing user to change the text of a div

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.

http://jsfiddle.net/qbXcw/11/

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

Answers (2)

Sunil B N
Sunil B N

Reputation: 4225

 <div id="allowedit" contenteditable="true">
  CLICK BUTTON TO EDIT THIS TEXT        
 </div>

Upvotes: 1

karaxuna
karaxuna

Reputation: 26930

You can use html attribute contenteditable

<div contenteditable="true">
  This text can be edited by the user.
</div>

Upvotes: 12

Related Questions