How to display the information in the referenced id?

Asked

Viewed 29 times

1

This function is the final part of my code, it is working correctly, therefore I am not able to get the result in the place where I wish, which is in the div which has a tag with an ID. How do I have the result displayed in this ID?

function DisplayInfo()
{
var expdate = new Date();
var visit;
expdate.setTime(expdate.getTime()+(24 * 60 * 60 * 1000 * 365));
if(!(visit = GetCookie("visit")))
visit = 0;
visit ++ ;
SetCookie("visit", visit, expdate, "/", null, false);
document.write(visit); 
}
document.getElementById("count").onload=DisplayInfo();

HTML where to display the result in the correct location:

<div class="col-sm-2 col-4 text-center">
                    <p id="title_cont">Visitante:</p>
                    <p id="count" onload="DisplayInfo()"></p>
                </div>
  • 1

    with document.write will not "write" to the element, use the getElementById and then change his content

1 answer

1


Hello, good afternoon!

The comment Ricardo made is correct, just to clarify:

Subastitua

document.write(visit);

For

document.getElementById('count').innerHTML = visit

I hope I helped, good luck!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.