Javascript development

Asked

Viewed 39 times

1

You have been asked to create a function that changes the paragraph to bold when the mouse is positioned over it. However, I am not able to solve. If anyone can help me, below part of the code made.

function changeTipo(){
    document.getElementById('paragra').style.font-weight.bold;
}

<p id = "paragra" onMouseOver = "changeTipo()">Texto Texto Texto Texto Texto Texto TextoTexto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto.</p>

1 answer

4


Your syntax to set the property is incorrect, the right is: fontWeight = 'bold'

I took and also added the type, so if it is 'over' you arrow to Bold the property if it is not reset to normal.

function changeTipo(tipo) {
  document.getElementById('paragra').style.fontWeight = tipo == 'over' ? 'bold' : 'normal';
}
<p id="paragra" onMouseOver="changeTipo('over')" onMouseOut="changeTipo('')">Texto Texto Texto Texto Texto Texto TextoTexto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto Texto.</p>

Browser other questions tagged

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