Advertisement
tourniquet

jQuery replace links

Nov 5th, 2015
577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <div id="desc">
  2.     <a href="https://domain1.com/product-6456.html">Пример 1</a>
  3.     <a href="/product-6456.html">Пример 2</a>
  4.     <a href="https://domain1.com/product-12.html">Пример 3</a>
  5.     <a href="https://newdomain.com/product-1-562.html">Пример 4</a>
  6. </div>
  7.  
  8.  
  9. $('#desc').children().each(function() {
  10.   const value = $(this).attr('href')
  11.  
  12.   if ($(this).attr('href').indexOf('domain1') !== -1)
  13.     $(this).attr('href', value.replace('domain1', 'some'))
  14. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement