Andi Crew
Andi Crew

Reputation: 129

location by id js?

How to make, that by pressing "a" in the "div" the opening window should be between "div".

Pressed "id 2", the window was displayed between "id 1" and "id 3". Pressed "id 3", the window displayed between "id 2" and "id 4".

 $('#add').hide();
 
 $('#open_add').click(function() {
        $('#add').show(); 
        $('#3').hide();
     });
     
 $('#close_add').click(function() {
        $('#add').hide();    
        $('#3').show();
     });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<div id="add">
<a href="#" id="close_add">Close add</a>
</div>

<div id="1">
  <p>First</p>
</div>

<div id="2">
  <p>Second</p>
</div>

<div id="3">
  <a href="#" id="open_add">Open add</a>
</div>

<div id="4">
  <p>Fourth</p>
</div>

<div id="5">
  <p>Fifth</p>
</div>

Upvotes: 1

Views: 164

Answers (1)

Artem Kolodko
Artem Kolodko

Reputation: 409

Try to insert div like is this example:

$(document).ready(function( ){
$('div p').click(function() {
$('#add').remove().insertAfter($(this).parent()).show();
})
})
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="add" style="display:none;">
<a href="#" id="close_add">Close add</a>
</div>
<div id="open_add" style="display:none;">
<a href="#" id="open_add">Open add</a>
</div>

<div id="1">
  <p>First</p>
</div>

<div id="2">
  <p>Second</p>
</div>

<div id="3">
  <p>Third</p>
</div>

<div id="4">
  <p>Fourth</p>
</div>

<div id="5">
  <p>Fifth</p>
</div>

Upvotes: 1

Related Questions