How can I change the color of the variable in JS dom?

Hamdysaad20

I want to change the color of my text that I displayed on the html by JS on hover here is the HTML :

<div class="text_user_info" id="tui"  onmouseover="hoverText()" onmouseout="noHoverText()" ></div>

Here is the JS :

 var userName = "Hamdy"
  var userNamef = userName.bold()
  const welcome = "Hello,  "

  document.getElementById("tui").innerHTML = welcome + userNamef;
DCR

just create your functions hoverText and noHoverText and set the style.color as needed

var userName = "Hamdy"
  var userNamef = userName.bold()
  const welcome = "Hello,  "

  document.getElementById("tui").innerHTML = welcome + '<span id="s">'+userNamef + '</span>';
  
  function hoverText(){
    let div = document.getElementById('s')
    div.style.color='blue'
    }
    
    function noHoverText(){
    let div = document.getElementById('s')
    div.style.color='black'
    }
<div class="text_user_info" id="tui"  onmouseover="hoverText()" onmouseout="noHoverText()" ></div>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related