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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:38:31+00:00 2026-05-28T05:38:31+00:00

I basically search for an element with specific data-attributes, so I loop through all

  • 0

I basically search for an element with specific data-attributes, so I loop through all of the elements with the class that might have those data-attributes. I loop with the jQuery each() function and already read and experienced that it is quite often pretty slow in IE7 or any other IE compared to the other common browsers like Firefox, Chrome or Safari.

Maybe there’s a better way to find these elements ?!

$('body').on('mouseenter', '.course', function(){
        var startday = $(this).data('start');
        var endday = $(this).data('end');
        var coursemonth = $(this).data('month');

        $('.dayname').each(function() {
            var thisday = $(this).data('date');
            var thismonth = $(this).data('month');

            if(thisday >= startday && thisday <= endday && thismonth == coursemonth)
            {
                $(this).addClass('red');
            }
        })
});

The context I’m looping through with the .each() is a list of days, actually just all the 30 or how many days in a month and this for up to 6 month. Each day contains the date in the format ‘mmdd’ and also the month as a data attribute.

            <div class="dayname we" data-date="0401" data-month="04">So</div>
            <div class="dayname " data-date="0402" data-month="04">Mo</div>
            <div class="dayname " data-date="0403" data-month="04">Di</div>
            <div class="dayname " data-date="0404" data-month="04">Mi</div>
            <div class="dayname " data-date="0405" data-month="04">Do</div>

Update: Unfortunately all tips and hints to increase the performance of selectors and elements in the each failed. But I still hope to be able to get this to work. I don’t really have a proper idea, but I somehow have the feeling that there might be a way with something like find() and a selector that is able to differ between higher and lower numbers as (as you can see in the markup) my data attributes are just numbers.
Is there a way out there with comparison in the selector ? That way I could omit the .each() and hopefully outrun the performance problem with that.

  • 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-05-28T05:38:32+00:00Added an answer on May 28, 2026 at 5:38 am

    You can optimize your code to help improve the performance by reducing the number of calls to data method and also creating jQuery object instance of this element.

    var $dayName = $('.dayname');
    $('body').on('mouseenter', '.course', function(){
            var dataObj = $(this).data();
    
            $dayName.each(function() {
                var $this = $(this);
                var innerDataObj = $this.data();
    
                if(innerDataObj.date >= dataObj.start 
                   && innerDataObj.date <= dataObj.end 
                   && innerDataObj.month == dataObj.month)
                {
                    $this.addClass('red');
                }
            })
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to search elements based on data attributes? I have the
I have a simple script that does some search and replace. This is basically
I have been trying to search answer for this, but all discussions that I
I'm trying to basically do a search through the database with Perl to tell
I've got a search results page that basically consists of a repeater with content
I will be starting a simple datastore-and-search project soon. Basically, one of those put
Basically I have some code to check a specific directory to see if an
I have a kinda complex query, basically I search the database in most fields
I want to create a really simple search form, basically a single field, that
I have been trying to get this to work. Basically I have a search

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.