7

What sort of selector would be I need in order to insert after the parent (divouter) of the test3 class in the example below? Thanks.

<div class='divouter'>
    <div class='divinner'>
        <input class=test1></input>
    </div>
</div>
<div class='divouter'>
    <div class='divinner'>
        <input class=test2></input>
    </div>
</div>
<div class='divouter'>
    <div class='divinner'>
        <input class=test3></input>
    </div>
</div>
<div class='divouter'>
    <div class='divinner'>
        <input class=test4></input>
    </div>
</div>
usertest
  • 27,132
  • 30
  • 72
  • 94

3 Answers3

16

You could use the $.after() method:

$(".test3").closest(".divouter").after("<div>Foo</div>");

Or the $.insertAfter() method:

$("<div>Foo</div>").insertAfter( $(".test3").closest(".divouter") );
Sampson
  • 265,109
  • 74
  • 539
  • 565
0
.divouter:parent
roman
  • 11,143
  • 1
  • 31
  • 42
0

I think you want the "after()" method:

$('input.test3').focus(function() {
   $(this).closest('div.divouter').after('<div>Hi!</div>');
});
Pointy
  • 405,095
  • 59
  • 585
  • 614