views:

22

answers:

1

Hello, 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:

Error: 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);
}
A: 

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).

Reigel
Thanks a lot, now I feel little stupid, because I've tried a lot of things, except your simple solution. Now it works as it should. Also thanks for posting demo - it seems I have discovered useful tool for testing - jsfiddle.net.
Frodik
You're most welcome...
Reigel