Hello. There are markup

<b id="idname">some_content</b> 

How to turn it into

 <b id="idname">some_content2</b> 

Regular?

 $("#elementID").html("another string"); 

In my case, it’s not completely dead Thank.

  • one
    what do you mean by regular expression ??? - qwabra
  • Something like this <b (. *?) B>. To capture an element directly, without "penetrating" into the DOM - Lebedev
  • And you did not think just the text in the element to change? - Danil Chugaev

1 answer 1

Well, for those who wish, play a guessing game

 document.body.innerHTML = '<b id="idname">some_content</b>' void function () { let i = 0 function foo() { var idname = idname || document.getElementById('idname') let str = `some_content_${i}` let tmp_d = document.createElement('div') tmp_d.innerHTML = idname.outerHTML.replace(/(?![^>]+>)(.*)(?=<[^>]+>)/g, `>${str}`) idname.parentElement.replaceChild(tmp_d.childNodes[0], idname) i++ if (i > 20) clearInterval(intervalID) } let intervalID = setInterval(foo, 1000) }() 

  • The answer should contain clear information on the topic, not a random flow of thoughts. "Markup" is an absolutely correct term for the sequence of characters that the author cited. - MSDN.WhiteKnight
  • @ MSDN.WhiteKnight following your logic: before the word stop, I argue that changing the markup through the regular schedule is impossible - the answer is not absolutely true, but correct. And the phrase © To capture an element directly, without “penetrating” into the DOM - also does not bother you? - qwabra
  • @ MSDN.WhiteKnight, and yes, I do not understand your fanatical categorical, given the possibility of editing the answer. - qwabra 10:49 pm