Paranoik,
<!DOCTYPE html>
<html>
<head>
<script>
function $replace(name,text) {
let type;
if (name[0] == "#") {
let name1 = name.slice(1);
type = [document.getElementById(name1)];
}
else type = document.getElementsByTagName(name);
for (let i = 0; i < type.length; i++) {
type[i].innerHTML = text;
}
}</script>
</head>
<body>
<p>ПАРА</p>
<p id="p">ПАРА</p>
<p>ПАРА</p>
<script>
$replace("p","обама лох");
</script>
<p id = "test">ПАРА</p>
<script>
$replace("#test","ёжик в тумане");
</script>
</body>
</html>