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

  • Home
  • SEARCH
  • 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 8878049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:37:08+00:00 2026-06-14T19:37:08+00:00

Is it possible to access an HTML attribute value in SASS? I have a

  • 0

Is it possible to access an HTML attribute value in SASS?
I have a line of code that says

<ul id="my_id" data-count="3">

where the 3 is the result of some jQuery stuff. I need the 3 to calculate some CSS. How can I save it as a SASS variable?

Alternatively, is there a way of counting the number of child elements of a certain parent element? Say I have this code:

<ul id="my_id" data-count="3">
    <li>First list item</li>
    <li>Second list item</li>
    <li>Third list item</li>
</ul>

(As you might have guessed, the value of data-count matches the number of list items.) Can SASS count the list items and save that number as a variable?

Any ideas would be greatly appreciated.

  • 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-14T19:37:09+00:00Added an answer on June 14, 2026 at 7:37 pm

    Sass is just a CSS generator. It doesn’t really interact with your HTML, so you can’t use HTML attributes as Sass variables.

    However, CSS can select based on attributes. So it will be more long-winded than you might like, but you can do something like

    ul[data-count="3"]:after
      content: "There were three items in that list!"
    

    And I think if you’re willing to limit yourself only to a subset of very recent browsers†, you can use the CSS calc() function along with attr() to use the attribute in CSS-based calculations. But that’s pretty bleeding edge.

    † To be perfectly honest, I have no idea which versions of which browsers have fully implemented this. I’m pretty sure Firefox has it, though I’ve not used it, and I have no idea about other browsers. It is certainly not well-supported, at any rate.

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

Sidebar

Related Questions

example.html contains: <a href=mypage.html data-str=foo>Test</a> Is it possible to access the value of data-str
Is it possible to access an XML section / node using an attribute value
I understand that it is not quite possible to access webcam through HTML. So
Is it possible to access the Data Purge Tool from the Valence API?
It is possible to retrieve the bitmap data HTML Canvas 2D element, is it
It is possible to access HTML DOM from an applet using netscape.javascript JSObject API.
I have a <p> tag without an id attribute that I'd like to remove.
Is it possible to call or access HTML file which exists in another apk
Possible Duplicate: Access Control Allow Origin not allowed by I have a problem when
Is it possible to access a class member without an instance of the class?

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.