admin管理员组文章数量:1313598
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?
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?
Share Improve this question asked Apr 12, 2012 at 9:41 Aen TanAen Tan 3,3456 gold badges35 silver badges53 bronze badges 4- 1 setup a fiddle on jsfiddle showing your problem – Baz1nga Commented Apr 12, 2012 at 9:42
- 1 What do you mean by 'focus effect'? Neither of these appear to have it: jsfiddle/aSPKQ – Rory McCrossan Commented Apr 12, 2012 at 9:44
- I realize I had some other click events interfering. It does work. My bad. The question is kind of invalid. What should I do with it? – Aen Tan Commented Apr 12, 2012 at 10:34
- I am facing same issue , Unable to make editable div focus on single click -- Let me know if you have solution – Vivek Panday Commented Jun 11, 2015 at 10:24
3 Answers
Reset to default 5I realized I'm having this problem because the element is also a jquery-ui draggable and the click event has been hijacked.
http://jsfiddle/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')
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.
本文标签: javascriptDIV with added contenteditablequottruequot does not focus on clickStack Overflow
版权声明:本文标题:javascript - DIV with added contenteditable="true" does not focus on click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741949988a2406655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论