admin管理员组

文章数量:1023242

I am developing an interface, which allows a user to edit a div by right clicking on the div. I have been able to achieve this using jquery.

After the user is done editing, and the mouse moves out of the div, I want the div to bee non-editable as before. I figured out that I can use mouseleave function of jquery, but I am not sure where exactly this should be written. I tried using the mouseevent as shown below, but it does not work.

$(".list").contextMenu({
        menu: 'listMenu'
    },
    function(action, el, pos) {
        if(action=='edit'){
            $(el).attr('contenteditable','true');
            $(e1).mouseleave(function() {
                $(e1).attr('contenteditable','false');
        });
    }
});

I am developing an interface, which allows a user to edit a div by right clicking on the div. I have been able to achieve this using jquery.

After the user is done editing, and the mouse moves out of the div, I want the div to bee non-editable as before. I figured out that I can use mouseleave function of jquery, but I am not sure where exactly this should be written. I tried using the mouseevent as shown below, but it does not work.

$(".list").contextMenu({
        menu: 'listMenu'
    },
    function(action, el, pos) {
        if(action=='edit'){
            $(el).attr('contenteditable','true');
            $(e1).mouseleave(function() {
                $(e1).attr('contenteditable','false');
        });
    }
});
Share Improve this question edited Jun 11, 2013 at 13:07 Erik Schierboom 16.7k10 gold badges66 silver badges81 bronze badges asked Jun 11, 2013 at 11:33 user1628340user1628340 9414 gold badges14 silver badges29 bronze badges 3
  • 1 What is e1? Possible el? (small L on end) – maximkou Commented Jun 11, 2013 at 11:36
  • 1 Change "e1" to "el" and then tell us what is the problem. – gkalpak Commented Jun 11, 2013 at 11:37
  • 2 The typo ExpertSystem and maximkou already mentioned is the problem :). You've mispelled el (a lower case EL) as e1 (a lower case E and a one). – juan.facorro Commented Jun 11, 2013 at 11:38
Add a ment  | 

1 Answer 1

Reset to default 6

Try to use prop() instad:

$( el ).prop('contenteditable', false );

&&

$( el ).prop('contenteditable', true );
  • note that I'm using Boolen values, not string.

And as mentioned in ments you have a typo: e1 should be el

I am developing an interface, which allows a user to edit a div by right clicking on the div. I have been able to achieve this using jquery.

After the user is done editing, and the mouse moves out of the div, I want the div to bee non-editable as before. I figured out that I can use mouseleave function of jquery, but I am not sure where exactly this should be written. I tried using the mouseevent as shown below, but it does not work.

$(".list").contextMenu({
        menu: 'listMenu'
    },
    function(action, el, pos) {
        if(action=='edit'){
            $(el).attr('contenteditable','true');
            $(e1).mouseleave(function() {
                $(e1).attr('contenteditable','false');
        });
    }
});

I am developing an interface, which allows a user to edit a div by right clicking on the div. I have been able to achieve this using jquery.

After the user is done editing, and the mouse moves out of the div, I want the div to bee non-editable as before. I figured out that I can use mouseleave function of jquery, but I am not sure where exactly this should be written. I tried using the mouseevent as shown below, but it does not work.

$(".list").contextMenu({
        menu: 'listMenu'
    },
    function(action, el, pos) {
        if(action=='edit'){
            $(el).attr('contenteditable','true');
            $(e1).mouseleave(function() {
                $(e1).attr('contenteditable','false');
        });
    }
});
Share Improve this question edited Jun 11, 2013 at 13:07 Erik Schierboom 16.7k10 gold badges66 silver badges81 bronze badges asked Jun 11, 2013 at 11:33 user1628340user1628340 9414 gold badges14 silver badges29 bronze badges 3
  • 1 What is e1? Possible el? (small L on end) – maximkou Commented Jun 11, 2013 at 11:36
  • 1 Change "e1" to "el" and then tell us what is the problem. – gkalpak Commented Jun 11, 2013 at 11:37
  • 2 The typo ExpertSystem and maximkou already mentioned is the problem :). You've mispelled el (a lower case EL) as e1 (a lower case E and a one). – juan.facorro Commented Jun 11, 2013 at 11:38
Add a ment  | 

1 Answer 1

Reset to default 6

Try to use prop() instad:

$( el ).prop('contenteditable', false );

&&

$( el ).prop('contenteditable', true );
  • note that I'm using Boolen values, not string.

And as mentioned in ments you have a typo: e1 should be el

本文标签: javascriptRemoving contenteditable attribute on mouseleaveStack Overflow