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

438
Visualizações
Hide Option within Select box using Jquery / Javascript

I'm looking to hide just one option within a select box using Jquery/Javascript. I've tried CSS to display: none but it doesn't work on all browsers and I can't edit the option directly to add "hidden" or similar.

https://impactdigitaldev.co.uk/bookly/

In the first drop-down "category" I'm trying to hide the "lane hire" option. Which you can see has a value="5" so I've tried the following script but it's not working if you have any suggestions I'd be really grateful.

$("#cats option[value='5']").remove();

I also tried without the ID and still no luck

$("option[value='5']").remove();
about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

$("select option[value='5']").remove()
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<select>
<option value="0">Category</option>
   <option value="1">coaching</option>
   <option value="5">lane hire</option>
</select>

Working fiddle https://codepen.io/hermes14/pen/VwyrXjr?editors=1111

about 4 years ago · Juan Pablo Isaza Relatório

0

$("#cats option[value='5']").remove();

Does work, you've got an uncaught type error in your console though which probably is why the script doesn't run.

As you can see in the screenshot below I ran your snippet in the browser console, resulting in a removed option.

enter image description here

In case you are interested, this can be easily handled through regular javascript as such:

document.querySelector("#cats option[value='5']").remove();
<div class="bookly-form-group" id="cats" data-type="category">
<label>Category</label> 
  <div>
    <select>
      <option value="0">Category</option>
      <option value="1">coaching</option>
      <option value="5">lane hire</option>
    </select>
  </div> 
</div>

about 4 years ago · Juan Pablo Isaza Relatório

0

You don't need to escape the block quote:

document.querySelector("option[value='5']").remove();
<select>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
    <option value="6">6</option>
    <option value="7">7</option>
    <option value="8">8</option>
    <option value="9">9</option>
    <option value="10">10</option>
<select>

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