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

129
Visualizações
jQuery custom attr is not working in option tag

I have select type with having custom attr in option tag. When i am able to get the val, but not able to get the value in custom attribute.

Here is Jsfiddle

JSFIDDLE

<script>
    jQuery(document).on('change','.selectedItem',function() {
    
        var selectedValue = jQuery(this).val();
        alert(selectedValue);
        alert(jQuery(this).attr("id"));
        var product_id = jQuery(this).attr('rel-product-id');
        alert(product_id);
        var product_name= jQuery(this).attr("rel-product-name");
        alert(product_name);
        
        });
    </script>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So the problem is that you're trying to get the values of the attributes from the select itself. What you want to do is to get them from the selected option of the select using option:selected. Like this:

alert(jQuery('option:selected', this).attr('id'));
alert(jQuery('option:selected', this).attr('rel-product-id'));
alert(jQuery('option:selected', this).attr('rel-product-name'));
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