I’m just trying to replace a link with some text, so I’m trying to use .after(), and then hide(). The link is hidden, but the replacement text does not appear.
var the_link = $(this);
$(the_link).after('Replacement Text');
$(the_link).hide();
What’s wrong here? The examples I see online make this seem like it should work.
The below sample works fine for me.
<a id="the_link" href="">Test Link</a>
<script>
$(document).ready(function() {
$('#the_link').after('Replacement Text');
$('#the_link').hide();
});
</script>
I suspect something else may be effecting your code. Can you show the rest of the code?
I suspect that since I was dealing with a link that was not always the same link, and I had to use “this”, that somehow the usage was affected. Since I am bound by contract not to show the code, I can’t post the actual code, but I fixed my problem by chaining hide on to the end of after:
$(the_link).after('Replacement Text').hide();
It’s things like this that make me stumble. Why the above code works but the original code doesn’t is beyond my knowledge of javascript and jquery.