HTML5 contentEditable with jQuery

前端 未结 5 1352
情深已故
情深已故 2021-01-04 00:59

I have some elements that need to have the text inside editable, for this I am using the HTML 5 attribute contentEditable. I can\'t seem to do use jQuery for this using mult

5条回答
  •  北荒
    北荒 (楼主)
    2021-01-04 01:53

    I get the impression you're misunderstanding the problem in two places:

    1. jQuery creates "query" objects which provide a shorthand for manipulating sets of DOM elements. Your example code sets contentEditable on the query, not what it matches. You want jQuery's shorthand for "set an attribute on all matching elements", which is $('whatever').attr('contentEditable','true');

    2. I'm not sure you understand contentEditable properly. You're supposed to set it on the top-level container for each editable region and its effects apply to everything within. In my experience, if setting contentEditable on#container or something like #container div.post really isn't good enough, then you've got bigger problems.

提交回复
热议问题