Jamen Jamen - 4 years ago 140
Javascript Question

How to make an element's content editable with JavaScript (or jQuery)

How would I make it so the content of an element could be made editable through native JavaScript (DOM) and/or jQuery?

Answer Source

Solution to toggle editable on/off using a click handler:

$('button').click(function(){
    var $div=$('div'), isEditable=$div.is('.editable');
    $div.prop('contenteditable',!isEditable).toggleClass('editable')
})

DEMO

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download