How can I actually edit a HTML element with JavaScript, just like you do in the dev console by clicking “Edit as HTML”

Disclaimer: I am a massive beginner

So I was having fun with JavaScript and I wondered if instead of using innerHTML if you wanted to change the text or style.color for css fun or whatever (I am a beginner to all of this) you can actually rewrite the element, like if I wanted to target the title of this question as an example, should look probably something like this in the html:

<a href="/questions/78202361/how-can-i-actually-edit-a-html-element-with-javascript-just-like-you-do-in-the" class="question-hyperlink">How can I actually edit a HTML element with JavaScript, just like you do in the dev console by clicking "Edit as HTML"</a>

and lets say with JavaScript I want to edit the color, so adding […]just <span style="color:red">like</span> you do in […] (I used […] to skip some text cause of my long question)

Basically my question is if I can retype a element completely within a script, or maybe you have to cut it, change it, and then create a new one.

I didn’t find the answer nowhere else or maybe I’m just using the wrong terms