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

214
Visualizações
How to change URL address(details) by jQuery or JavaScript?

My English in not good. sorry.

URL address example:

example.com/action.php?id=1&name=JOHN&email=JONH@EXAMPLE.COM

I want change "name" only:

example.com/action.php?id=1&name=JACK&email=JONH@EXAMPLE.COM

by Jquery or JavaScript Click Function.

I found a solution but I do not want to write everything again. I want to call name=JOHN and turn it into name=JACK.

I do not want is:

$('.element').click(function () {
window.location = 'action.php?id=1&name=JACK&email=JONH@EXAMPLE.COM';
});
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I assume your link is in an href in an <a> element .

You change change the href (or any attribute) value with the JQuery attr() function:

element.on(“click”, function () {
    $(this).attr(“href”, “ example.com/action.php?id=1&name=JACK&email=JONH@EXAMPLE.COM”);
});

Here element is the element on which you need to click, could also be a JQuery call $(“#elementID”). The this object refers in this context to the object being clicked on, so the element. If we wrap ‘this’ in a JQuery selector you can acces JQuery methods on that element, which would be .attr(). See the docs for further documentation: https://api.jquery.com/attr/

about 4 years ago · Juan Pablo Isaza Relatório

0

You can split the string by a question mark (?) to get the parameters, then use the URLSearchParams constructor to parse it and URLSearchParams.set to set the name parameter to "JACK":

const url = "example.com/action.php?id=1&name=JOHN&email=JONH@EXAMPLE.COM";

const split = url.split('?');

const params = new URLSearchParams(split[1]);

params.set('name', 'JACK')

const result = split[0] + params.toString();
console.log(result)

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