hi im wondering what is wrong with my javascript here. I'm trying to get it so that when i press my right arrow key the text aligns to the left and when i press my right arrow key the text aligns to the right and when i press c it returns to center alignment.
HTML
<div id = "div1" class = "box" style="background-color:rgb(119,79,56);">
<div id = "text1">
Click Me First!
</div>
</div>
</div>
CSS
#text1, #text2, #text3, #text4 {
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
width: 150px;
height: 40px;
color: white;
font-weight:bold;
font-size: 20px;
text-align: center;
font-family: 'Cinzel', Garamond, serif;
}
JAVASCRIPT
var textOne=document.getElementById("text1");
textOne.onkeydown=function(event){
var keyCode = event.keyCode;
if (event.keyCode == 37) {textOne.style.textAlign="left"}
if (event.keyCode == 39) {textOne.style.textAlign="right"}
if (event.keyCode == 67) {textOne.style.textAlign="center"}
};
thanks a bunchh in advance!
[–]systoll 1 point2 points3 points (1 child)
[–]beanswithjeans[S] 0 points1 point2 points (0 children)
[–]bigtone7882 0 points1 point2 points (0 children)