eba
eba

Reputation: 673

jquery remove breaks markup

Have such code:

<div style="position:relative">
    <div id="t1" style="position:relative; top:100; left:100;"></div>
    <div id="t2" style="position:relative; top:200; left:200;"></div>
</div>

<script>
$(function () {
    $('#t1').remove();
);
</script>

after that script div-t2 is moving randomly to another place, and if i remove t2, then t1 moves. how to make their position stable, i dont want them to travel on my screen.

Upvotes: 1

Views: 125

Answers (4)

Oundless
Oundless

Reputation: 5505

The positions of t1 and t2 are relative to where they would be in the normal run of HTML rendering.

To achieve what you want, make the position of t1 and t2 absolute.

Upvotes: 1

Thariama
Thariama

Reputation: 50832

Give them (the inner divs) style="position:absolute".

Upvotes: 0

Gabriele Petrioli
Gabriele Petrioli

Reputation: 195992

Use absolute positioning

<div style="position:relative">
    <div id="t1" style="position:absolute; top:100px; left:100px;"></div>
    <div id="t2" style="position:absolute; top:200px; left:200px;"></div>
</div>

and also add a unit to your position values (i have added px)

Upvotes: 1

jAndy
jAndy

Reputation: 235992

change position: relative to position: absolute (relative to the parent) or position: fixed (relative to the document)

Upvotes: 2

Related Questions