Satch3000 Satch3000 - 1 month ago 9
Javascript Question

JQuery Toggle property contentEditable = "true"

I am using contenteditable="true" in a div

What I want to do it to toggle true and false on this attribute everytime I click on a div.

example:

$( "#mylabel" ).click(function() {
$('#editablediv').attr('contenteditable','false');
});


I tried:

$( "#mylabel" ).toggle(function() {
$('#editablediv').attr('contenteditable','false');
});


but that didn't work

How can I do this?

Answer

Try this way:

$( "#mylabel" ).click(function() {
    var value = $('#editablediv').attr('contenteditable');

    if (value == 'false') {
        $('#editablediv').attr('contenteditable','true');
    }
    else {
        $('#editablediv').attr('contenteditable','false');
    }
});

Keep me posted, hope this helped