afro360 afro360 - 7 months ago 11
Javascript Question

Jquery if contenteditable=true event

Im trying to detect if the element I have clicked on is contentEditable. I have tried this:

$( "#thediv" ).hide();
$(this).click(function() {
if ($(this).is("[contenteditable='true']")) {
return true;
$( "#thediv" ).show();
alert('hi');
} else if ($(this).is("[contenteditable='false']")) {
return false;
$( "#thediv" ).hide();
alert('hi');
}
});


AND

$( "#thediv" ).hide();

$(this).click(function() {
if ($(this).attr("contentEditable") == true) {
$( "#thediv" ).show();
alert('yes');
} else {
$( "#thediv" ).hide();
alert('no');
}
});


How can I get this to work?

Here's a fiddle

Answer

You have your element hiding the hello. Here Ya go http://jsfiddle.net/dqEE2/2/

$( "#hello" ).hide();  
$(function() {
    $("div").click(function() {
        if ($(this).attr("contentEditable") == "true") {
            $( "#hello" ).show();
            alert("yes");
        } else {
            alert("no");
          $( "#hello" ).hide(); 
        }
    });