Removing text from text returned by javascript function

Keywords´╝Ü javascript html

Question: 

I have a function that returns text but I need to remove a specific substring from the returned text. I've tried a bunch of variations on suggestions I found through stackoverflow but none have worked so far. Any advice?

<div id="textfunction">
  <script>
    $().ready(function(){" "}
    {console.log(
      $("#textfunction")
        .load("https://example.com/").text().replace("substring",""))}
    );
  </script>
</div>

I'd like to get: "Returned text: ." Instead, I'm getting: "Returned text: substring."

Answers: