Html在div里面添加父元素,向父div添加一个div元素

本文探讨了使用CKEditor时遇到的问题,特别是当用户删除子元素后无法正确地在剩余子元素之后添加新子元素的情况。作者尝试了多种jQuery方法但未能解决此问题,并寻求帮助。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I have one application, which allows users to enter multiple comments into multiple text boxes. Presently I am using the Ck editor tool. I have 4 divs which all are placed in a parent div. We call shift the position of child div up and down and also we can delete the div. When I try to delete the div, it goes and if the user clicks on the add, it should come.

My problem is when I am trying to add the new child div, it will not come under the existing remaining div. I have tried to use Append(), AppendTo(), Insert(), InsertAfter(), etc, but unfortunately with no luck. Can you guys please help me wash out this issue?

Here is one code snippet:

var children = $('#editors').children(); // Editors is a Parent Div.

var childrenCount = children.length;

if (childrenCount == 1) {

if (SectionName == 'Statement') {

$('#p0').insert("#p" + (children[0].id).toString());

Talk1:

it will not come under the existing remaining div, but does it appear nowhere or somewhere else? and why moest childrenCount be 1? more explanation please.

Talk2:

By default the children Count will be 4. If the user delete the divs it comes up to 1. After that User can't delete the remaining one. If the user is trying to add the new div. It should place after the existing child div.

Solutions1

I don't understand exactly what you are trying to achieve, but maybe something like this might help

$("#p0").append($("#p" + (children[0].id).toString()).html());

Solutions2

If I am understanding the issue correctly, you should be able to do something like:

$("

Test
").appendTo("#editors");

That will append the new div after the one that is still in your parent div.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值