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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:55:15+00:00 2026-06-14T16:55:15+00:00

I have a HTML section like this: <li data-file=file.mp3> <div class=pink-light playing> Now, I

  • 0

I have a HTML section like this:

<li data-file="file.mp3">
    <div class="pink-light playing">

Now, I want to get the “data-file” attribute of <li>.
But I have several <li> tags, and I want to get only the
attribute that has a div with “playing” class inside.

My script:

$(".playing").before($("li"),function(){

    alert($(this).attr("data-file"));

});

What is wrong?

Thanks!

  • 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-14T16:55:16+00:00Added an answer on June 14, 2026 at 4:55 pm

    There are a couple of ways of doing it. If the .playing element will be unique, then:

    var file = $(".playing").closest("li").attr("data-file");
    

    closest finds the closest ancestor that matches a given selector. Since your .playing element is a child (descendant) of the li, that’s how you can find it.

    Alternately, you could use the :has pseudo-class:

    var file = $("li:has(.playing)").attr('data-file');
    

    …but be aware that :has is a jQuery thing, so it can’t delegate to the selector engine.

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

Sidebar

Related Questions

I have HTML like this: <div> <a href=>sometext<img src=images/001.jpg /></a> <a href=>sometext<img src=images/002.jpg /></a>
I want to have a comments section in my app that looks like this:
I have an HTML form with sections laid out like this: I do want
I have this html: <div id=h101 data-stellar-ratio=6><img src=images/h1_01.png width=600></div> <div id=cloud01 data-stellar-ratio=0.5><img src=images/cloud_01-s.png></div> <div
On a blog detail page, I have a tags section. The html looks like:
I have the following HTML: <section id=sidebar class=grid_3> <section id=content class=grid_9> I used jQuery
I have HTML like this: <article> <header> <hgroup> <h1>Wk 25 </h1> <h2>(18-06 tot 24-06)</h2>
I have an HTML file (from Newegg) and their HTML is organized like below.
I have an XML file generated using javax.sql.rowset.WebRowSet.writeXml which looks like: <metadata> This section
I have some data from an Nmap Scan. It looks like this. Nmap scan

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.