M
M
Mikhail Gilmutdinov2018-03-20 21:27:24
JavaScript
Mikhail Gilmutdinov, 2018-03-20 21:27:24

How to find a word in a div block and give it a class, using JS, which is written in capital LETTERS?

How to find a word in a div block and give it a class, using JS, which is written in capital LETTERS?

for example

<div class="block">
  <h1>СЛОВО большими буквами</h1>
</div>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-03-20
@Mixailhr

How to find a word in a div and give it a class...

What does it mean to assign a class to a word? No, seriously - do you understand what you said?
You can wrap the found word in a span with the desired class :
block.innerHTML = block.innerHTML.replace(/([А-Я]+)/g, '<span class="здесь-ваш-класс">$1</span>');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question