I want to activate CSS using JS. Let's say I have this code, and I want to enlarge a picture at first click and then send it to the right after at the second click, but it's not working. Is the function correct?
How can I use JavaScript to control the CSS of an element?
<script>
function function(){
var house = document.getElementById("house");
if(this.className == "mystyle")
this.className = "mystyle2";
else
this.className = "mystyle";
}
</script>
<a href="#" style="text-decoration: none"><img src="casa1.jpg" id="house" width="200" height="150" onclick="function()">
I want it to activate this CSS:
.mystyle {
position: absolute;
left: 50%;
margin-left: -100px;
}
.mystyle2{
float: right;
}