Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

239
Visualizações
How to find and repalce anchor tag link inside td in php

I am working with wordpress,I want to change "url"(product link) of "product-image" in "cart" page, So i have following code (dynamic)

<td class="product-name" data-title="Product">
<a href="abc.com/en/product/basic-c-organic/">Basic-C-Organic</a>
</td>

How can i change the url of this product with jquery,I tried with following code but not working,how can i do this ?

var product = $('.product-name').next("a").text();
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You need to "find" the the a tag and the change the link with the .attr() of jquery

var product = $('.product-name').find("a").attr("href", "https://www.whatever-you-like.com");
about 4 years ago · Juan Pablo Isaza Relatório

0

You can do it like below:

var urlReplacement = $('.product-name a').text();
var url = $('.product-name a').attr("href");
var pathComponent = url.split('/');
pathComponent[ pathComponent.length-1 ] = urlReplacement;
url = pathComponent.join('/');
$('.product-name a').attr("href", url);

Running example:

var urlReplacement = $('.product-name a').text();
var url = $('.product-name a').attr("href");
var pathComponent = url.split('/');
pathComponent[ pathComponent.length-1 ] = urlReplacement;
url = pathComponent.join('/');
$('.product-name a').attr("href", url);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tr>
<td class="product-name" data-title="Product">
<a href="abc.com/en/product/basic-c-organic">delat-Organic</a>
</td>
</tr>
</table>

Note: Now based on the product name (link text), the link URL will change dynamically once the page is loaded.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda