admin管理员组文章数量:1023838
I have a contenteditable div
. Inside, I have put a 'fraction' span, with regards to this link. Here's my current code (the numbers in the spans are just dummy numbers):
<span style="display:inline-block; vertical-align:middle;" contenteditable="false">
<span style="display:block; min-width: 20px;border-bottom:1px solid black; text-align: center; outline: none;" contenteditable>6</span>
<span style="display:block; min-width: 20px;text-align: center;outline: none;" contenteditable>7</span>
</span>
My problem is, when I try to delete this 'fraction' span (the outer span, and it should be deletable, as this is a Maths WYSIWYG Program), it just removes the content of the two inner contenteditable spans. When I try to delete it (obviously from outside the outer span but inside the contenteditable div), I want all three elements to get removed. I don't want the outer span still lingering.
Any solutions?
UPDATE: If there is no way to do this, is there a way to select that whole span element and its contents when the user presses the delete key next to the big fraction span?
I have a contenteditable div
. Inside, I have put a 'fraction' span, with regards to this link. Here's my current code (the numbers in the spans are just dummy numbers):
<span style="display:inline-block; vertical-align:middle;" contenteditable="false">
<span style="display:block; min-width: 20px;border-bottom:1px solid black; text-align: center; outline: none;" contenteditable>6</span>
<span style="display:block; min-width: 20px;text-align: center;outline: none;" contenteditable>7</span>
</span>
My problem is, when I try to delete this 'fraction' span (the outer span, and it should be deletable, as this is a Maths WYSIWYG Program), it just removes the content of the two inner contenteditable spans. When I try to delete it (obviously from outside the outer span but inside the contenteditable div), I want all three elements to get removed. I don't want the outer span still lingering.
Any solutions?
UPDATE: If there is no way to do this, is there a way to select that whole span element and its contents when the user presses the delete key next to the big fraction span?
Share Improve this question edited May 23, 2017 at 10:34 CommunityBot 11 silver badge asked Aug 29, 2012 at 7:06 ZeriumZerium 17.4k32 gold badges118 silver badges187 bronze badges 2- Could you show what you tried? Or at least a bit of js to better understand your issue? – Gil Zumbrunnen Commented Aug 29, 2012 at 7:22
- No it's actually simple enough - I'm trying to create a Maths WYSIWYG Program as mentioned above, and I'm stuck on the part where after a user creates a 'fraction', they have difficulty deleting it. – Zerium Commented Aug 29, 2012 at 7:25
1 Answer
Reset to default 3Just provide the top span with an id:
<span id="editfraction"
style="display:inline-block; vertical-align:middle;"
contenteditable="false">
and use this to delete it:
$('#editfraction').remove();
If you want to delete the span when the user presses the delete button, use ids, bined with a data attribute on the contentEditable spans.
<span ... data-ondeleteId="#editx" contenteditable>6</span>
See this jsfiddle for an example
I have a contenteditable div
. Inside, I have put a 'fraction' span, with regards to this link. Here's my current code (the numbers in the spans are just dummy numbers):
<span style="display:inline-block; vertical-align:middle;" contenteditable="false">
<span style="display:block; min-width: 20px;border-bottom:1px solid black; text-align: center; outline: none;" contenteditable>6</span>
<span style="display:block; min-width: 20px;text-align: center;outline: none;" contenteditable>7</span>
</span>
My problem is, when I try to delete this 'fraction' span (the outer span, and it should be deletable, as this is a Maths WYSIWYG Program), it just removes the content of the two inner contenteditable spans. When I try to delete it (obviously from outside the outer span but inside the contenteditable div), I want all three elements to get removed. I don't want the outer span still lingering.
Any solutions?
UPDATE: If there is no way to do this, is there a way to select that whole span element and its contents when the user presses the delete key next to the big fraction span?
I have a contenteditable div
. Inside, I have put a 'fraction' span, with regards to this link. Here's my current code (the numbers in the spans are just dummy numbers):
<span style="display:inline-block; vertical-align:middle;" contenteditable="false">
<span style="display:block; min-width: 20px;border-bottom:1px solid black; text-align: center; outline: none;" contenteditable>6</span>
<span style="display:block; min-width: 20px;text-align: center;outline: none;" contenteditable>7</span>
</span>
My problem is, when I try to delete this 'fraction' span (the outer span, and it should be deletable, as this is a Maths WYSIWYG Program), it just removes the content of the two inner contenteditable spans. When I try to delete it (obviously from outside the outer span but inside the contenteditable div), I want all three elements to get removed. I don't want the outer span still lingering.
Any solutions?
UPDATE: If there is no way to do this, is there a way to select that whole span element and its contents when the user presses the delete key next to the big fraction span?
Share Improve this question edited May 23, 2017 at 10:34 CommunityBot 11 silver badge asked Aug 29, 2012 at 7:06 ZeriumZerium 17.4k32 gold badges118 silver badges187 bronze badges 2- Could you show what you tried? Or at least a bit of js to better understand your issue? – Gil Zumbrunnen Commented Aug 29, 2012 at 7:22
- No it's actually simple enough - I'm trying to create a Maths WYSIWYG Program as mentioned above, and I'm stuck on the part where after a user creates a 'fraction', they have difficulty deleting it. – Zerium Commented Aug 29, 2012 at 7:25
1 Answer
Reset to default 3Just provide the top span with an id:
<span id="editfraction"
style="display:inline-block; vertical-align:middle;"
contenteditable="false">
and use this to delete it:
$('#editfraction').remove();
If you want to delete the span when the user presses the delete button, use ids, bined with a data attribute on the contentEditable spans.
<span ... data-ondeleteId="#editx" contenteditable>6</span>
See this jsfiddle for an example
本文标签: javascriptHow to delete whole span element with contenteditable spans inside itStack Overflow
版权声明:本文标题:javascript - How to delete whole span element with contenteditable spans inside it? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745533692a2154864.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论