You can put all your #m1
...#m9
divs into .target
and display them based on fragment identifier (hash) using :target
pseudo-class. It doesn't move the contents between divs, but I think the effect is close to what you wanted to achieve.
HTML
<div class="target">
<div id="m1">
dasdasdasd m1
</div>
<!-- etc... -->
<div id="m9">
dasdasdsgaswa m9
</div>
</div>
CSS
.target {
width:50%;
height:200px;
border:solid black 1px;
}
.target > div {
display:none;
}
.target > div:target{
display:block;
}