KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I am curious why jQuery's .after() does not chain, or "provide you with," the new element that you create with it. It seems to me like it should, but I am no expert and was hoping someone could shed some light on why it's a bad idea. Here's an example to see what I would like from .after(): Here is some markup: <div id="content1"> <p id="hello1">Hello</p> </div> <div id="content2"> <p id="hello2">Hello</p> </div> Here's what I want, but this replaces "Hello" with "World!": $('#hello1').after('<p />').text('World!'); This does the job, but it sure is ugly: $('#hello2').after('<p />'); var $newParagraph = $('#content2 p').last(); $newParagraph.text('World'); This is nicer, but I'm not entirely sold: (maybe I should be?) $('#hello1').after( $('<p />').text('World') ); Note this is obviously a simplified example, that is, "<p>World!</p>" is not what I want to add, my real world problem is more complex than that. Thanks for any thoughts.
Tags (comma-separated)
Save Edits
Cancel