Reputation: 9
Basically I have three div
element, And I want to append child element <P>
after <div class="div1"></div>
.
my code is:
<div class="div1">
<p></p>
<section class="section"></section>
</div>
<div class="div2"></div>
i have try this one
$('.div1').appendChild('<p>hello world!!</p>');
Upvotes: 0
Views: 218
Reputation: 5352
$('.div1+.div2').before('<p>hello world!!</p>');
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<div class="div1">
<p>test1</p>
<section class="section"></section>
</div>
<div class="div2">
<p>test2</p>
</div>
Upvotes: 1
Reputation: 74738
It should be .after()
:
$('.div1').after('<p>hello world!!</p>');
$('.div1').after('<p>new p</p>');
div{border:red solid 1px;}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="div1">
<p>inner p in div1 </p>
<section class="section">inner section in div 1</section>
</div>
<div class="div2">div 2</div>
Upvotes: 1