javascript - Removing contenteditable attribute on mouseleave - Stack Overflow

I am developing an interface, which allows a user to edit a div by right clicking on the div. I have be

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745576281a4633981.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信