开发者

Append li after current li

开发者 https://www.devze.com 2023-02-05 05:46 出处:网络
I would like to append a li in a ul after my current selection. I bound a click event to the li, and when it\'s clicked, another li has to be added 开发者_如何学Pythonafter the current.

I would like to append a li in a ul after my current selection.

I bound a click event to the li, and when it's clicked, another li has to be added 开发者_如何学Pythonafter the current.

What I have now is:

$(this).parent().append('<li>test</li>');

But this just adds the li to the ul, not after the current li.

Is there a way to do that?

Thanks in advance


Use the quite aptly-named .after() method:

$(this).after('<li>test</li>');


Use insertAfter() and pass your this as the argument.

0

精彩评论

暂无评论...
验证码 换一张
取 消