Solution 1 :

On the server side, it would be an obvious place to not show a link

EJS

<p class="vocab paragraph inherit-colored info__content info__content-creator">
  <% if (creatorUrl) { %>
    <a href="<%= creatorUrl %>">Creator Name</a>
  <% } else { %>
    Creator Name
  <% } %>
</p>

On the client side you can do this to replace empty links with their textContent

window.addEventListener("load",function() {
  [...document.querySelectorAll(".info__content-creator a[href^='#']")].forEach(lnk => lnk.parentNode.replaceChild(document.createTextNode(lnk.textContent), lnk));
})
<p class="vocab paragraph inherit-colored info__content info__content-creator">
  <a href="#">Creator Name</a>
</p>

<p class="vocab paragraph inherit-colored info__content info__content-creator">
  <a href="createorpage.html">Creator Name</a>
</p>

Solution 2 :

var a = document.getElementById(‘yourlinkId’); //Give your anchor tag an Id or select it however you want and store it in a variable.

 if(!creatorUrl){
    a.href = '#';
    }
  else{
  a.href = "somelink url"
 }

Problem :

I have a bug to fix in my code

  if (!creatorUrl) {
        creatorUrl = '#';
      }

Basically what the above code does is, it checks if the creator has a URL to which I can redirect the user, otherwise I don’t want to do anything.

  <p class="vocab paragraph inherit-colored info__content info__content-creator">
                <a href="creator_url">Creator Name</a>
              </p>

This is the tag which I am modifying. I want the expected behaviour to be like, when the creatorUrl doesn’t exist,the Link shouldn’t show up at all and the creator name should be a plain text.How can I do this ?

Comments

Comment posted by Luca

If you want to set the url like this inside the html, you have to start over. Post all the code please

Comment posted by mplungjan

OP wants to not have a link at all if there is no href

Comment posted by mplungjan

that is assuming that I am all about the rep. I have 100K+ so no that is not it. I come from somewhere and attempt to encourage people to read and answer the question. Do not feel discouraged. Just try harder. If you fix your answer I will remove the downvote, if you improve the answer enough I wil even vote it up. At least use a ternary

Comment posted by mplungjan

Your answer COULD have been

By