Как отобразить жирный текст в
, когда контент добавляется с помощью JS?Javascript

Форум по Javascript
Anonymous
Как отобразить жирный текст в
, когда контент добавляется с помощью JS?

Сообщение Anonymous »

Второй элемент не отображает ожидаемый результат. Почему и как исправить?

Код: Выделить всё

function process(sentence,element) {

const words = sentence.split(' ');
const container = document.getElementById(element);
let index = 0;

container.innerHTML = '';

for (let i = 0; i < words.length; i++) {
//console.log(words[i]);
container.innerHTML += words[i] + ' '; // Display the word
}
}

process("the quick fox[/b] jumps",'e1');   //displayed the word 'fox' as expected in bold[b]process("the quick  fox [/b] jumps",'e2'); //displayed the word 'fox' as plain text, not as expected

Код: Выделить всё

div{
border:1px solid #999;
margin: 0 0 10px 0;
display:block;
font-size:22px
}



Подробнее здесь: https://stackoverflow.com/questions/793 ... dded-by-js

Вернуться в «Javascript»