title: Refer to ID (as selector) that is already inside HTML link tags
body: <p>I have a link that is generated by a core module (meaning I can't modify the code) as such:</p>
  
  <pre><code>&lt;a id="my-unique-id-1" class="my-link-class" href="/switch off"&gt;Switch off&lt;/a&gt;
  </code></pre>
  
  <p>Problem is, the ID and class are within the <code>&lt;a&gt;</code> tag and I do not have any useable elements wrapped around the link that I can use.</p>
  
  <p>When clicked, it goes and do what it has to do server side (see code following), and then returns this:</p>
  
  <pre><code>&lt;a id="my-unique-id-1" class="my-link-class it-is-off" href="/switch on"&gt;Switch on&lt;/a&gt;
  </code></pre>
  
  <p>I want to replace or amend the complete first link.</p>
  
  <p>First the jQuery script:</p>
  
  <pre><code>$(".my-link-class").click(function() {
    var current_id = $(this).attr('id');
    var link = $(this).attr('href');
  
    $.ajax({url: link, success: function (result) {
    //All works fine up to here. The changes are made in server side and returns the new link as the result. 
  //Following is my problem:
  
      if(result){ 
        $(current_id).replaceWith(result); //the selector is wrong, I know.
      }
    }
  }
  </code></pre>
  
  <p>My problem is that the id (current_id) is already within a <code>&lt;a&gt;</code> tag.
  How can I refer to the selector in the tag.
  I tried: </p>
  
  <pre><code>$(current_id).replaceWith(result); //nothing happens
  $('#' + current_id).replaceWith(result);
  $('a#' + current_id).replaceWith(result);
  </code></pre>
  
  <p>But I get with the last two TypeError: Argument 1 of Node.appendChild does not implement interface Node.</p>
  
  <p>(I know I can do other things than replaceWith such as changing text and href in link, but the problem here is to find the selector first).</p>