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 caseEL
) ase1
(a lower case E and a one). – juan.facorro Commented Jun 11, 2013 at 11:38
1 Answer
Reset to default 6Try 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 caseEL
) ase1
(a lower case E and a one). – juan.facorro Commented Jun 11, 2013 at 11:38
1 Answer
Reset to default 6Try 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
版权声明:本文标题:javascript - Removing contenteditable attribute on mouseleave - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745576280a2157036.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论