How to close the link from indexing? Who thinks this?

Hello! Want to close the link from indexing using js. The script changes to the html code page is "supposedly" links to the normal link after full loading of the document.
Everything works, the tag <span></span> is replaced by <a></a>

How are the search engines?

<span class="hidden-link" data-link="cart.html"><span id="total-cart-count" class="badge"></span></span>


$('.hidden-link').replaceWith(function(){
 return'<a href="'+$(this).data('link')+'">'+$(this).html()+'</a>';
})
June 8th 19 at 16:55
2 answers
June 8th 19 at 16:57
Solution
What <noindex></noindex> not satisfied?
Well, like I asked another question - jairo51 commented on June 8th 19 at 17:00
,
return'<a class="basket" href="'+$(this).data('link')+'">'+$(this).html()+'<span id="total-cart-count" class="badge"></span></a>';

So it is impossible? - Izabella commented on June 8th 19 at 17:03
June 8th 19 at 16:59
Solution
You may want to try instead
$(this).html()
use
this.outerHTML
well, or innerHTML
but more like that should help outerHTML - jairo51 commented on June 8th 19 at 17:02
Does not help(( - Izabella commented on June 8th 19 at 17:05
may you have pasted the HTML already (or still) without attributes
washed down this code and look in the console what html "should" was inserted
$('.hidden-link.basket').replaceWith(function(){
console.log('$(this).html()');
console.log($(this).html());
console.log('this.outerHTML');
console.log(this.outerHTML);
console.log('this.innerHTML');
console.log(this.innerHTML);
 return '<a class="basket" href="' + $(this).data('link') + '">' + $(this).html() + '</a>';
});
- nikolas.Reichert commented on June 8th 19 at 17:08
All work in my code. Himself somewhere lohonulsya - jairo51 commented on June 8th 19 at 17:11
, well and good - nikolas.Reichert commented on June 8th 19 at 17:14

Find more questions by tags JavaScriptHTML