Aen Tan
Aen Tan

Reputation: 3345

DIV with added contenteditable="true" does not focus on click

I'm using jQuery to add the content editable attribute to a DIV.

$('div').attr('contenteditable', 'true');

When I click it, I don't get the focus effect I get when I click on already contenteditable DIVs. It only focus when I click it another time.

This happens in every single one of my browsers – Safari 5, Chrome 18, Firefox 8. Is there anyway I can make it behave as it should?

Upvotes: 5

Views: 4629

Answers (3)

davidmars
davidmars

Reputation: 689

I had the same bug trying to add the contenteditable attribute on a mouse event. Using the mousedown event, it doesn't work. Using the click event it works fine...

The id attribute doesn't change anything in my case.

Upvotes: 1

Aen Tan
Aen Tan

Reputation: 3345

I realized I'm having this problem because the element is also a jquery-ui draggable and the click event has been hijacked.

Upvotes: 5

cosmorogers
cosmorogers

Reputation: 453

http://jsfiddle.net/VV7BW/1/ seems to work. $('div') might be your problem, that will get all divs I think, but only apply the attr to the first one (but don't quote me on this)

Try giving your div an id, then access it with $('#id')

Upvotes: 1

Related Questions