I have the following code
img.after('<li></li>');
Which works correctly and add the “li” element. Now I want to select the “li” element; it doesn’t have any class or ID, but I want to select it just after creating it, so I’m able to use it (for example mynewli.addClass()) as a jquery element.
How can I do that?
Use
.insertAfter()to be able to chain, which is the heart ofjQuery.edit
In respect of your comment, use
onto your cached
imgelement. Note that this won’t guarantee that you select a specificelement, it’ll just select that next
lielement. So I still suggest to use.insertAfter()and cache that newly created item into a variable, to access later.Reference: .insertAfter()