Html elementine bir id değeri ver. Js içerisinden elementi getElementById ile al.
Daha sonra innerText, innerHTML özelliğini kullanarak Text değerini değiştir.
Yok amacım o değil, şöyle bir otomatik bot konuşması var;
- Hi.
+ Hello.
- How are you?
+ I'm good, thanks. How are you?
- I'm good, thanks.
+ Okay, bye..
- Bye..
Şeklinde, bu konuşma ekranın sol üstünde çıkıyor, ama ben bu konuşmayı HTML ve CSS ile yaptığım dikdörtgenin içine taşımak istiyorum.
[CODE lang="javascript" title="JavaScript" highlight="70"]function chats(){
setTimeout(join1, 3000);
setTimeout(join2, 4000);
setTimeout(k1, 6000);
setTimeout(k2, 8000);
setTimeout(k3, 10000);
setTimeout(k4, 12000);
setTimeout(k5, 13500);
setTimeout(k6, 16500);
setTimeout(k7, 19500);
setTimeout(left1, 21800);
setTimeout(left2, 23000);
let user1 = "User1: ";
let user2 = "User2: ";
function join1(){
document.write("User1 has joined the chat! <br>")
}
function join2(){
document.write("User2 has joined the chat! <br>")
}
function k1(){
document.write(user1 + "Hi. <br>")
}
function k2(){
document.write(user2 + "Hello. <br>")
}
function k3(){
document.write(user1 + "How are you? <br>")
}
function k4(){
document.write(user2 + "I'm good, thanks. How are you? <br>")
}
function k5(){
document.write(user1 + "I'm good, thanks. <br>")
}
function k6(){
document.write(user2 + "Okay, bye.. <br>")
}
function k7(){
document.write(user1 + "Bye.. <br>")
}
function left1(){
document.write("User2 has left the chat! <br>")
}
function left2(){
document.write("User1 has left the chat!")
}
}
chats();[/CODE]
[CODE lang="html" title="HTML" highlight="40"]<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
*{
color: white;
}
#chat{
background-color: black;
width: 500px;
height: 600px;
margin: auto;
border: 10px solid rgb(95, 95, 95);
padding: 13px;
color: white;
}
</style>
<body>
<div id="chat">
</div>
</body>
</html>[/CODE]
Şunu denedim, fakat undefined sonucunu aldım;
document.getElementById("chat").innerHTML = chats();
Belki bu kodu yanlış şekilde kullanmışımdır.