开发者

Error when removing contentEditable attribute using JQuery in FF and Opera, works in Chrome

I have problem with this piece of code:

var el = $('div#editor');
el.find('*[contentEditable]').removeAttr('contentEditable');

It works great in Chrome 4/5/6, but it doesn't work in FF (3.6.) or Opera (10.60).

In FF it throws this exception:

Err开发者_JAVA技巧or: uncaught exception: [Exception... "An invalid or illegal string was specified" code: "12" nsresult: "0x8053000c (NS_ERROR_DOM_SYNTAX_ERR)" location: "http://www.www.com/js/script.js Line: 51"]

Does anybody have an idea why this is happening and how to fix it ?

Right now I am using this fix, but it's not clean solution, because it leaves contentEditable attribute and I have to clean it up on server side:

try {  
  el.find('*[contentEditable]').removeAttr('contentEditable');
} catch (e) {
  el.find('*[contentEditable]').attr('contentEditable', false);
}


works fine to me...

html

<div contenteditable="true">testing....</div>

jQuery

$('[contenteditable]').removeAttr('contenteditable');

maybe try all small letters on contenteditable and remove * on $('*[contenteditable]')

demo

tested on FF (3.6.) or Opera (10.10).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜