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

112
Visualizações
Compare and match last part of URL with and accented/unaccented input value

I want to match the last part of the site url with an input value. This string starts with #.

The input value can have accents or not.

This is what I have right now:

  $(function () {
    var loc = window.location.href.split("#")[0]; // returns the full URL

    var href = location.href;
    var hrefM = href.match(/#([^\/]*)\/*$/)[1];
    var hreflocation = hrefM.replace(/-/g, " ").toProperCase();

    if (hreflocation) {
      $(".wpcf7-list-item :input[value= '" + hreflocation + "' ]").parent().addClass("active");
      $(".wpcf7-list-item :input[value= '" + hreflocation + "' ]").attr("checked",true);
    }
  });

It works fine when there are no accents. Do you know how to adjust my hrefM so that although this word has no accents it is the same as an input with accents?

For example, this comparison doesn't work right now:

url hreflocation = "#produccio"
<input value="producció">

But this comparison works well:

url hreflocation = "#produccio"
<input value="produccio">
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First, I'd like to point out a few things.

  1. The text after the # in the URL is called the hash, and you can access it with location.hash.
  2. <String>.toProperCase is not a function.
  3. You cannot match all possible latin diacritics and variations in an attribute selector.

You can instead do:

$(function() {
  if (location.hash) {
    const hash = location.hash.substring(1).replaceAll('-', ' ');
    const matchedInput = $(".wpcf7-list-item input").toArray()
      .find(input => input.value.normalize('NFKD').replace(/\p{Diacritic}/gu, '') == hash);
  }
});
  • hash takes the location hash, removes the #, and converts all - to
  • $(".wpcf7-list-item input").toArray() selects all input elements inside the .wpcf7-list-item and converts them to an array (to allow you to process them with JavaScript)
  • .find looks for an element in the array whose value, when normalized and stripped of diacritics, is equal to hash

You can then use $(matchedInput) however you want. If you instead want an array of matched inputs, you can replace find with filter.

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