Search code examples
javascriptjqueryhtmlcontenteditable

How to remove tag attribute from all other tags?


I'm using following code to add 'contenteditable', true when double click on particular table td. When I click on particular td I want to 'contenteditable', false for all other table td s. I tried it on following way $("#contentsTable > td").prop('contenteditable', false); but it not working. How I do this?

$(document).on('dblclick', 'td', function(){
    $("#contentsTable > td").prop('contenteditable', false);
    $(this).prop('contenteditable', true); 
});

Solution

  • The td is not the direct child of table element so nothing get selected when using > with your selector. So remove the direct child(>) selector from the selector string to make it work.

    $("#contentsTable td").prop('contenteditable', false);