Reputation: 3
I'm working on a chat program. (javascript/html/css) How can I put the focus on the field where i want to write my message?
Normally it's css code, isn't it?
The css of my message field looks like this right now:
Code:
#messageField {
width: 600px;
margin: 20px auto;
border: 1px solid #5a2300;
}
What do I have to add to the cursor there when my app starts?
Greetings
Upvotes: 0
Views: 84
Reputation: 12633
<head>
<script type="text/javascript">
function setFocus() {
document.getElementById("messageField").focus();
}
</script>
</head>
<body onload="setFocus()">
</body>
Upvotes: 3
Reputation: 9701
If the id is bind to an input
or textarea
element, you can simply add this:
#messageField:focus {
width: 600px;
margin: 20px auto;
border: 1px solid #5a2300;
}
Upvotes: 0