Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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')
    } )
  );
);

-> Please see my jsfiddle for examples (test case)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
189 views
Welcome To Ask or Share your Answers For Others

1 Answer

This may be the naive answer:

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

Seems to work...

EDIT: have I missed the point here? http://jsfiddle.net/wFx9Z/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...