Are you first timer at lazacode.org? Why not join us and start exchange your knowledge with everyone. Register today!

jQuery .before() and .after() method

0 votes
12 views
added Apr 13 in jQuery by LC Marshal Second Warrant Officer (6,010 points)
edited Apr 13 by LC Marshal

Add <p>Hey I'm here</p> .before .inner2

<div class="container">
  <h1>Hey</h1>
  <div class="inner1">Hello</div>
  <div class="inner2">Goodbye</div>
</div>
$( ".inner2" ).before( "<p>Hey I'm here</p>" );
//HTML output
<div class="container">
  <h1>Hey</h1>
  <div class="inner1">Hello</div>
  <p>Hey I'm here</p>
  <div class="inner2">Goodbye</div>
</div>

 

Add <p>Hey I'm here</p> .after .inner2

<div class="container">
  <h1>Hey</h1>
  <div class="inner1">Hello</div>
  <div class="inner2">Goodbye</div>
</div>
$( ".inner2" ).after( "<p>Hey I'm here</p>" );
//HTML output
<div class="container">
  <h1>Hey</h1>
  <div class="inner1">Hello</div>
  <div class="inner2">Goodbye</div>
  <p>Hey I'm here</p>
</div>

Please log in or register to example this solution.

lazacode.org - Malaysia based Knowledge Exchange Platform, where you can share your finding or solution with other members of community.
...