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

554
Visualizações
Safari jquery select option .hide() alternative

I have a jquery script which at first hide all select options:

$('option[data-start="1"]').hide();

and then shows options based on user select of other input.

$('option[data-variable1="' + variable1x + '"][data-variable2="' + variable2x + '"]').show();

Everything works great, but on Safari .hide() doesn't work. I know about workaround:

$('option[data-start="1"]').prop('disabled', true);
$('option[data-variable1="' + variable1x + '"][data-variable2="' + variable2x + '"]').prop('disabled', false);

But this only turns off some options. I have dozens of options, so there is long list of inactive options. I tried hiding inactive options, but Safari probably ignores this code:

select option[disabled="disabled"]{display:none !important;width:0;height:0;visibility: hidden;opacity:0;}
select option:disabled { display:none !important;height:0;width:0;visibility: hidden;opacity:0;}

Could you help me with some workaround for Safari?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

to get a full browser compatible to hide and show elements try to use the hidden attribute https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/hidden

to use it in your code to hide option

$('option[data-start="1"]').attr('hidden','hidden');

and to show an option use

$('option[data-start="1"]').removeAttr('hidden','hidden');

here a working fiddle https://jsfiddle.net/zj2kLxc8/1/

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