<h5>Пластиковое окно "Эконом"</h5> 

It is required that in quotes select in the span. I know that you can use regular expressions.

It is necessary to become so

 <h5>Пластиковое окно "<span>Эконом</span>"</h5> 

    2 answers 2

     var h5 = document.getElementsByTagName('h5')[0], str = h5.innerHTML, p1 = str.indexOf('"'), part1 = str.slice(0, p1), world = str.slice(p1+1, str.lastIndexOf('"')); h5.innerHTML = part1 + '"<span>' + world + '</span>"'; 
     <h5>Пластиковое окно "Эконом"</h5> 

    And a shorter solution:

     var h5 = document.getElementsByTagName('h5')[0]; h5.innerHTML = h5.innerHTML.replace(/(.+)"(.+)"/, '$1"<span>$2</span>"'); console.log(h5.innerHTML); 
     <h5>Пластиковое окно "Эконом"</h5> 

    • @lendik, added a shorter solution. - Bharata

    text.replace (/ Economy / g, "Economy"))

    • I need any text to be in quotes - lendik
    • Using the regular form /".+"/ look for the text in quotes. After the same expression is used in the replace, but there you replace it with the found string in the last step using a variable. PS can be done without using a preliminary search - JavaJunior