Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
How can I assign a function to <span>? To display a number in a span

How can I assign a function to ? To display a number in a span Screуnshot Please tell me how can I do this? Created with React Js

function onlineCount() {
  Math.floor(100+480*Math.random()); 
}

setInterval(onlineCount, 1000);

function HeaderTop() {
  
  // const onlineCount = Math.floor(100+480*Math.random()) 

  return (
    <div className="header-top">
        <div className="header-social">
        <div className="header-online">
          <div className="online-general-bar">
            <div className="online-bar"></div>
          </div>
          <span>{() => onlineCount}</span>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

REACT

const root = ReactDOM.createRoot(
  document.getElementById('root')
);

function tick() {
  const element = (
    <span>{Math.floor(100 + 480 * Math.random());
            setTimeout(function () { onlineCount(); }, 1000);}
    </span>
  );
  root.render(element);
}

setInterval(tick, 1000);

PURE JAVASCRIPT

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript">
        function onlineCount() {
            document.getElementById("mySpan").innerText = Math.floor(100 + 480 * Math.random());
            setTimeout(function () { onlineCount(); }, 1000);
        }
        setTimeout(function () { onlineCount(); }, 1000);
    </script>
</head>
<body>
    <form id="form1">
        <div>
            <span id="mySpan"></span>
        </div>
    </form>
</body>
</html>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!