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

205
Views
Check if "data" attribute contains A PART of input value (jQuery)

With this way I only find the needed div, if the "data-content" contains the complete word.

var input = "TestText123";
var found = $("#list").find(".box[data-name='" + input + "']").addClass("found");

But I also want to find this div if my "input" just contains a correct part of it (min. 5 characters).

It's interesting, that this would work, if I don't use the "data" method (but I need it).

var found = $("#list").find(".box:contains('" + input + "')").addClass("found");

How to modify the "data" method in jQuery, like the way I need it?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Add an asterisk before the equal sign: [data-name*=...].

Side note: the argument of addClass should not have a dot, so just addClass("found"):

var input = "TestText123";
var found = $("#list").find(".box[data-name*='" + input + "']").addClass("found");
.found { background: yellow }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<ul id="list">
    <li class ="box" data-name="WhatTestText12345">should match</li>
</ul>

about 4 years ago · Santiago Trujillo Report
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!