javascript - jQuery check if element is editable - Stack Overflow

ProblemI have an editable div containing a few non-editable divs. If a user clicks somewhere I have to

Problem

I have an editable div containing a few non-editable divs. If a user clicks somewhere I have to find out if he clicked in an area he can actually edit or not.

Question

Is there a way to check if an element is editable? Something like this:

$('my-element-selector').is(':editable')

(And no, the :editable selector is not working, just an example)

Problem

I have an editable div containing a few non-editable divs. If a user clicks somewhere I have to find out if he clicked in an area he can actually edit or not.

Question

Is there a way to check if an element is editable? Something like this:

$('my-element-selector').is(':editable')

(And no, the :editable selector is not working, just an example)

Share Improve this question asked Jun 11, 2014 at 4:27 MarcMarc 6,7719 gold badges51 silver badges79 bronze badges 2
  • what do you mean by an editable div? – Alfred Huang Commented Jun 11, 2014 at 4:29
  • Div with setting contenteditable=true – Marc Commented Jun 11, 2014 at 4:31
Add a ment  | 

4 Answers 4

Reset to default 4
$('#mydiv').get(0).isContentEditable

https://developer.mozilla/en-US/docs/Web/API/HTMLElement.isContentEditable

As far as i heard, there is no such selector called :editable in core jquery, Try to make use of the attribute selector at this context,

$('my-element-selector').is('[contenteditable="true"]')

DEMO

Try this

$( "div" ).click(function() {
if ( $( this ).hasClass( "editable" ) ) {

}
});

OR

if ( $( "#myDiv" ).is( ".editable" ) ) {

}

Give a specific class for editable div and check for class. For example :

 if ( $( "#DivId").hasClass( "Editable" ) ) {}

Another way :

if ( $( "#DivId" ).is( ".Editable" ) ) {

   }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744238723a4564600.html

相关推荐

  • javascript - jQuery check if element is editable - Stack Overflow

    ProblemI have an editable div containing a few non-editable divs. If a user clicks somewhere I have to

    9天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信