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 8289387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:29:51+00:00 2026-06-08T12:29:51+00:00

I am using jquery right now to get the value for the id, like

  • 0

I am using jquery right now to get the value for the id, like in the code bellow:

<ul class="trf noborder" data-id="6581">
</ul> 

var ID = $("ul.trf").data('id');

How can I do this using pure javascript? Do I need to add a span class or something?

Ty

  • 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-06-08T12:29:53+00:00Added an answer on June 8, 2026 at 12:29 pm

    There are several ways to do it with pure javascript
    depending on your needs and what kind of performance you expect. Here is one way using an ID:

    <ul class="trf noborder" data-id="6581" id="myDiv">
    </ul> 
    
    <script type="text/javascript">
        var id = document.getElementById("myDiv").getAttribute("data-id");
    </script>
    

    Or you can try this if you want to target a specific UL without any ID

    <ul class="trf noborder" data-id="6581">
    </ul> 
    
    <script type="text/javascript">
        var id = document.getElementsByTagName("ul")[0].getAttribute("data-id");
    </script>
    

    But you will have to make sure that you use the right index, here it will retrieve the first UL on your page. You could also wrap it in another container:

    <div id="container">
        <ul class="trf noborder" data-id="6581"></ul> 
    </div>
    
    <script type="text/javascript">
         var container = document.getElementById("container");
         var id = container.getElementsByTagName("ul")[0].getAttribute("data-id");
    </script>
    

    And it will use the first UL inside of that container. Or the third if you do it like this:

     var id = container.getElementsByTagName("ul")[2].getAttribute("data-id");
    

    It’s based on the array index, 2 in this case (0, 1, 2 = third element)

    If you don’t want jQuery but still can be willing to use a library, look at http://sizzlejs.com which is a great selector engine (actually used by jQuery). With Sizzle you could do it like this:

    var id = Sizzle("ul[data-id]")[0].getAttribute("data-id");
    

    To get the data-id of the first UL on the page that has a data-id attribute specified.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Without using jQuery (can't get into why NOT right now) how do I disable
Right now I havae a menu, that I'm using jquery to do a fade
The idea of the code I´m developing right now is extracting data from a
I'm using Jquery and Ajax function to get data from MySql and put it
Hey right now I'm using jQuery and I have some global variables to hold
I've working on a project and I'm using some jquery plugins, right now I'm
What I am doing right now is using the HTML5 data attributes to hold
Hy guys! I have to make a sliding div (left-right) using jquery. This is
I am using jquery cluetip and i have a link at the top right
Trying to detect left click vs right click (without using jQuery!) and I have

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.