Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6363245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:00:50+00:00 2026-05-25T00:00:50+00:00

Is there a way to search elements based on data attributes? I have the

  • 0

Is there a way to search elements based on data attributes?

I have the following code and would like to know how can this be achieved

<UL>
    <LI data-relation_id=1/>
    <LI data-relation_id=1/>
    <LI data-relation_id=1/>
    <LI data-relation_id=2/>
    <LI data-relation_id=2/>
    <LI data-relation_id=2/>
    <LI data-relation_id=3/>
    <LI data-relation_id=3/>
    <LI data-relation_id=3/>
</UL>

On a click event I basically want to find out all the items that belong to a specific data-relation?

function getRelatedObjects(relationId){
   //Search all the li's and get the LI 
   //that have the data-relation_id== relationId

}

Can this be done using jquery?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T00:00:50+00:00Added an answer on May 25, 2026 at 12:00 am

    The data attribute is just an attribute, so you can use the attribute selector.

    $('li[data-relation_id='+relationId+']')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to search an XDocument without knowing the namespace? I have
Is there any way to search in XML doc with match case? In this
Is there a way to DRY this jQuery up? <script type=text/javascript> $('form input#search').watermark('search...'); </script>
Is there a way to search for multiple strings simultaneously in Vim? I recall
Is there a way to search for a file in a subversion repository? Something
Is there a way to search and eventually search and replace text in Visual
Is there a way to search, from a string, a line containing another string
Is there any way to keep search engines from indexing text ads? These are
Is there a reasonable way to search standards for programming and markup languages (specifically,
I'm curious if there's a way to search for files in the iPhone's directory

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.