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

217
Visualizações
retrieve the value of a button jquery

I have this:

 <div class="cable-config">
            <span>Select Entries</span>
          
            <div class="cable-choose">
              <button id="Home" value="5.00">50 Entries<br>$5.00</button>
              <button value="10.00">100 Entries<br>$10.00</button>
              <button>250 Entries<br>$25.00</button>
              <button>500 Entries<br>$50.00</button>
            </div>
            <p>By entering, you agree to our Terms of Service, Official Rules, and Privacy Policy.</p>
          </div>
      </div>

      <script>
         var buttonValue = ""
          $('button').on('click', function(){
            $('button').removeClass('active_button');
            $(this).addClass('active_button');
            // var fired_button = $(this).val();
            //  alert(fired_button);
        });

        //Home button active on page load
        $(document).ready(function(){
            $('#Home').addClass('active_button');
        });

what it does it on button click, set the class to active_button.

Now what I am trying to do is get the value of class active_button when I click a new button. As you can see, i try to retrieve the value of active_button, but it returns undefined. what am i doing wrong?

function myfunction() {
  var valueOfButton = $('active_button').val();
  console.log(valueOfButton);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<div class="cable-config">
  <span>Select Entries</span>

  <div class="cable-choose">
    <button id="Home" value="5.00">50 Entries<br>$5.00</button>
    <button value="10.00">100 Entries<br>$10.00</button>
    <button>250 Entries<br>$25.00</button>
    <button>500 Entries<br>$50.00</button>
  </div>
  <p>By entering, you agree to our Terms of Service, Official Rules, and Privacy Policy.</p>
</div>

<div class="product-price">
  <button onclick="myfunction()" class="cart-btn">Continue To Payment</button>
</div>

about 4 years ago · Juan Pablo Isaza
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