Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

225
Vistas
Is there a way that I can check if similar data attribute exists?

I'm aware that there's a way to check if an attribute exists by doing something like:

if ($("div").data('attr')) {
  // true
}

However, is there a way to to find attributes that are similar and check if they exist?

For example:

  • I have a .listing div which has data-dept="sales"
  • I have a .card div which has data-dept="sales-us"

If .card has a data-dept attribute that is similar to that of .listing, then I'm trying to append .card to .listing. If it doesn't match, then append .card to .listing[data-dept="other"].

var html = "<div class='card' data-dept='sales-us'>Test</div>";

if ($(".card").data("sales")) {
  $(".listing[data-dept='sales']").append(html);

} else {
  $(".listing[data-dept='other']").append(html);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Examples of what similar means in the context:

  1. If .card is [data-dept="sales-us"] and .listing is [data-dept="sales"], these are similar as both contain "sales".
  2. If .card is [data-dept="business"] and .listing is [data-dept="business-development"], these are similar as both contain "business".
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda