Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

window location href inside jquery replaceWith tag

thanks for the amazing community, i'm strugling with this code i'm tring to load href link with window.location.href + string '/1/' into my jquery replaceWith tag but no luck could you help me please this is my code:

var myhref=window.location.href+'/1/':
$j('.the-tag p').replaceWith('<a href="'.myhref.'">My Link</a>');

thank you for your help again

like image 841
riamo66 Avatar asked Mar 20 '26 13:03

riamo66


1 Answers

Are you trying to do something like below ? You need to include jquery library files, and then below will work. In the code I have fixed : at the end of line 1 to ;

var myhref = window.location.href + '/1/';
$('.the-tag p').replaceWith('<a href="' + myhref + '">My Link</a>');
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="the-tag">
  <p></p>
</div>
like image 60
A Paul Avatar answered Mar 23 '26 04:03

A Paul