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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:00:44+00:00 2026-06-18T20:00:44+00:00

Should be a simple thing, but I’m getting no where. I want to get

  • 0

Should be a simple thing, but I’m getting no where.

I want to get the number of elements with a given data-attribute value.

I have some html elements with various data-size=’values’. Need to get the number of items with each value.

If you look at the code below, I want to get the number of ‘p’ sizes and ‘l’ sizes

$('.overview li img').each(function () {

var s = $(this).data('size');

switch (s) {
    case 'p':
        r = 0.66667
        break;
    case 'l':
        r = 1.5
        break;
}

var imgW = $(this).css({
    width: h * r + 'px'
});

})

any help greatly appreciated

cheers
dave

  • 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-18T20:00:45+00:00Added an answer on June 18, 2026 at 8:00 pm

    You can just create a selector that looks for data-size=’p’ or data-size=’l’

    var pCount = $(".overview li img[data-size='p']").length
    var lCount = $(".overview li img[data-size='l']").length
    

    Also, you can use the selector to eliminate the switch statement to just loop over elements with data-size=’p’ or data-size=’l’.

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

Sidebar

Related Questions

This should be simple, but I'm getting confused. I have a parent/child tables -
This should have been a simple thing to sort but even after extensive research
I know this should be a simple thing, but I have so much coding
I have what should be a simple thing but my unfamiliarity with .NET and
This should be a very simple thing to have run, but for some reason
I have what I think should be a fairly simple mapping issue, but not
should be simple right? but have not found any anwsers :
I worked all afternoon on a simple thing but cannot seem to get it
This should be a pretty simple thing to do with Update Panels, but I'm
I think this should be a rather simple thing to do, but I'm completely

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.