79169348

Date: 2024-11-08 08:53:58
Score: 1
Natty:
Report link

i know this question is old but i think this short example could help others as well.

I would access the element by its ID and change the innerText.

  1. HMTL-Client side:

    function buttonSendStringFromInput(){ var string = document.getElementById("inputfield").innerText; socket.emit("getStringfromHTML", string); }

2.Node Express-Server side:

socket.on("getStringfromHTML", (string) => { console.log(string);

// string changes var stringNew = ....

socket.emit("getNewString", stringNew); // Your client re-render without page reload

socket.broadcast.emit("getNewString", stringNew); // Re-render for all clients who are conntected to your page });

  1. HMTL-Client side:
socket.on("getNewString", (string) => { console.log(string); document.getElementById("inputfield").innerText = string; });

There is no need to reload the page :)

Reasons:
  • Long answer (-0.5):
  • No code block (0.5):
  • Low reputation (1):
Posted by: Philipp