Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

226
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!