-4

Hi so I am making a portfolio and since my internet name is unofficialdxnny I wanted to make it so on the website when the viewer hovers on the name unofficialdxnny the <h1> changes to a different text. where the text would be my real name.

Is this possible?

unofficialdxnny
  • 105
  • 1
  • 7
  • Does this answer your question? [Change text on hover, then return to the previous text](https://stackoverflow.com/questions/9913293/change-text-on-hover-then-return-to-the-previous-text) – Andrew Morton Mar 13 '22 at 14:38
  • @AndrewMorton Kind of. however it doesn't make the original heading disappear it states the name before `unofficialdxnny` – unofficialdxnny Mar 13 '22 at 14:51
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Mar 14 '22 at 14:29

1 Answers1

0

//your text element
let text = document.getElementById("text");
//checks for hover
text.addEventListener("mouseenter", function( event ) {
   //sets text
   text.innerHTML = "test2";

     setTimeout(function() {
    //sets text after some time
    text.innerHTML = "test1";
  }, 500);
}, false);
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>hover text</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <h1 id="text">test1</h1>
    <script src="script.js"></script>
  </body>
</html>

hope this works

myrccar
  • 85
  • 1
  • 9
  • Welcome to StackOverflow. Good answers include some explanation of what was done to solve the problem—not just working code. – Sean Mar 13 '22 at 14:50
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 13 '22 at 19:29