Schimbare valoare class intre doua Div-uri
Scris: Lun Iul 02, 2012
Am incercat pentru doua div-uri cu doua clase "div1" si "div2" sa interschimb valoarea atributelor class prin " obiect.className="valoare" " dar nu functioneza. Trebuie sa folosesc alta functie?
Cod: SelectaĊ£i tot
<html>
<head>
<title>
exercitiu
</title>
<style type="text/css">
.div1{
position:absolute;
top:50px;
left:40px;
width:300px;
height:100px;
border:2px solid blue;
background-color:red;
}
.div2{
position:absolute;
left:200px;
top:400px;
width:100px;
height:300px;
border:2px solid red;
background-color:blue;
}
</style>
</head>
<body>
<div class="div1">
</div>
<div class="div2">
</div>
<form>
<input id="modifica" style="position:absolute;top:20px;left:20px;" value="interschimba" type="button">
</form>
<script type="text/javascript">
var aux=document.getElementById("modifica");
aux.onclick=function(){
elem=document.getElementsByTagName('div');
elem[0].className='div2';
elem[1].className='div1';
};
</script>
</body>
</html>