Search code examples
javascriptcontenteditable

Javascript contentEditable of certain classes only


I have the following script that makes an HTML page editable

document.body.contentEditable = 'true'; document.designMode='on';

I am wanting to only allow my users to edit sections with a class of "edit". Is this possible?


Solution

  • YOu can try to find all the elements with the class name 'edit' and change all off them like below.

    document.querySelectorAll('.edit').forEach(function(element){
        element.contentEditable = 'true';
    })