How do I rewrite .after( content, content )?

Posted by Evan Carroll on Stack Overflow See other posts from Stack Overflow or by Evan Carroll
Published on 2010-05-28T21:59:48Z Indexed on 2010/05/28 22:02 UTC
Read the original article Hit count: 260

Filed under:

I've got this form working, but according to my previous question it might not be supported: it isn't in the docs either way -- but the intention is pretty obvious in the code.

$(".section.warranty .warranty_checks :last").after(
  $('<div class="little check" />').click( function () {
      alert('hi')
  } )
  , $('<span>OEM</span>')  /*Notice this (a second) argument */
);

What this does is insert <div class="little check"> with a simple .click() callback, followed by a sibling of <span>OEM</span>. How else can I write this then? I'm having difficulty conjuring something working by chaining any combination of .after(), and .insertAfter()?

I would expect this to work, but it doesn't:

$(".section.warranty .warranty_checks :last").after(
  $('<div class="little check" />').click( function () {
      alert('hi')
  } ).after ( $('<span>OEM</span>')  )
);

I would also expect this to work, but it doesn't:

$(".section.warranty .warranty_checks :last").after(
  $('<span>OEM</span>').insertAfter(
    $('<div class="little check" />').click( function () {
       alert('hi')
    } )
  );
);

© Stack Overflow or respective owner

Related posts about jQuery