2

I have put a Javascript text element in an HTML div field and now I want the text color to be white. I also want to make a few other changes to the text. Now I wonder how I can style the text element or whether it can is possible in this form.

(Translated into Google Translate, may contain errors)

This is my javascript code:

var bghtooltipin = document.getElementById('bgh-tooltipin1');
var bghtooltipout = document.getElementById('bgh-tooltipout1');
bghtooltipin.addEventListener('mouseover', bghtooltipinmouseOver);
bghtooltipin.addEventListener('mouseout', bghtooltipoutmouseOut);

function bghtooltipinmouseOver() {
  bghtooltipout.innerHTML = 'Go to Login';
}

function bghtooltipoutmouseOut() {
  bghtooltipout.innerHTML = ' ';
}

3 Answers 3

1

there are 2 ways, either use css classes or direct style manipulation

var bghtooltipin = document.getElementById('bgh-tooltipin1');
var bghtooltipout = document.getElementById('bgh-tooltipout1');
bghtooltipin.addEventListener('mouseover', bghtooltipinmouseOver);
bghtooltipin.addEventListener('mouseout', bghtooltipoutmouseOut);

function bghtooltipinmouseOver() {
  bghtooltipout.innerHTML = 'Go to Login';
  bghtooltipin.style.color = "white";
}

function bghtooltipoutmouseOut() {
  bghtooltipout.innerHTML = ' ';
  bghtooltipin.style.color = "black";
}
<div id="bgh-tooltipin1">Test 1</div>
<div id="bgh-tooltipout1"></div>

Sign up to request clarification or add additional context in comments.

Comments

0

It looks like you want to change the text color when the user mouses over the button. CSS has a pseudo-class class that covers this usecase. Take a look at https://developer.mozilla.org/en-US/docs/Web/CSS/:hover

Comments

0

Thanks @Józef Podlecki now I would like to add a small transition to my text, so that the text when hovering after about 6 milliseconds. That would be my second change to the text.

Because I didn't manage that with the classic style element.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.