Estoy tratando de cambiar el texto a negrita, lo cual es muy difícil. Lo intenté muchas veces usando varias formas, por ejemplo:
//1: document.getElementById('boldtext').innerHTML = "<b>" += document.getElementById('boldtext').innerHTML += "</b>"; //which dosent work //2: document.getElementById('boldtext').bold(); //dosent work too¿Alguna idea sobre cómo poner texto en negrita en Javascript?
//My code so far: The whole code is this: function getSelectionText() { var text = ""; if (window.getSelection) { text = window.getSelection().toString(); } else if (document.selection && document.selection.type != "Control") { text = document.selection.createRange().text; } alert(text); }; let BoldButton = document.createElement('input'); /*boldbuttonlol*/ BoldButton.type = 'button'; BoldButton.value = 'bold highlighted text'; BoldButton.onclick = () => { getSelectionText(); }; document.body.appendChild(BoldButton);¡¡Gracias!!
simplemente usa
document.getElementById('boldtext').style.fontWeight = "bold";por favor intente esto
function makeMeBold() { document.getElementById('boldtext').style.fontWeight = "bold"; } <input id="makeBold" type="button" onclick="makeMeBold()" value="Click me"/> <div id="boldtext">Sample text to make bold</div>