Append li after current li
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.
精彩评论