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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:32:21+00:00 2026-06-11T06:32:21+00:00

How to build function to return object in jquery like this: <ul class=clearfix> <li

  • 0

How to build function to return object in jquery like this:

<ul class="clearfix">
  <li data-year="2011" data-month="1">Jan</li>
  <li data-year="2011" data-month="2">Feb</li>
  <li data-year="2012" data-month="3">Mar</li>
  <li data-year="2012" data-month="4">Apr</li>
  <li data-year="2012" data-month="5">May</li>
</ul>

Search for li item, find data-year and return an object with count of equal items, like that
{2011: 2, 2012: 3}

  • 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-11T06:32:23+00:00Added an answer on June 11, 2026 at 6:32 am
    function obj(ul) {
        return {
                   2011: $('li[data-year="2011"]', ul).length,
                   2012: $('li[data-year="2012"]', ul).length
               }
    }
    
    console.log(obj($('ul')))   
    

    http://jsfiddle.net/x2n7t/2/

    Update:

    var obj = {};
    
    $('ul li[data-year]').each(function(){
       var year = $(this).data('year');
       obj[year] = obj[year] ? obj[year] + 1 : 1
    })
    

    http://jsfiddle.net/x2n7t/3/

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

Sidebar

Related Questions

How can I build a function slice(x, n) which would return a list of
I'd like to build a function that returns false if it's been called less
Following problem: I would like to build a little clipboard with jQuery. I have
I have build a little function which returns a jQuery plugin applied to a
I'm trying to build a jQuery plugin that filters the provided jQuery object to
I've got a JavaScript object, built this way: function foo() { this.length = 0;
I'd like to build a function in Django that iterates over a set of
How would one return a class computed CSS property/property array? Like, if I have
Going through happstack-lite tutorial : we build functions that have return type of ServerPart
Does Actionscript have a built-in function that accepts a number and can return a

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.