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
max value of data attribute using jquery

i have multiple division with different data attribute value, with same class also need to get the value data-value using jquery. Example i have data-value groups 2, 3, 5 to get the desired result is 5 among the group

<div data-value="2" class="maindiv">test</div>
<div data-value="5" class="maindiv">test</div>
<div data-value="3" class="maindiv">test</div>
etc.
about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

There is no direct way but this will do

var dataList = $(".maindiv").map(function() {
    return parseInt($(this).attr("data-value"));
}).get();
console.log(Math.max.apply(null, dataList));

https://jsfiddle.net/pgbf3o9f/

about 4 years ago · Santiago Trujillo Relatório

0

You can try the $.each() method, like below:

var result = 0;

$('.maindiv').each(function(index) {
    if ($(this).data('value') > result) {
        result = $(this).data('value');
    }
});
// result now contains the max value, so do what you want with it
console.log(result);
about 4 years ago · Santiago Trujillo Relatório

0

You should try below code.

function MaxId(selector) {
    var max=null;
    $(selector).each(function() {
        var id = parseInt(this.id, 10);
        if (isNaN(id)) { return; }
        if ((max===null) || (id > max)) { max = id; }
    });
    return [max];
}
alert(MaxId('div.maindiv'));

or you can also try as below.

Math.max(one, two, three);
about 4 years ago · Santiago Trujillo 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