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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:21:27+00:00 2026-06-09T14:21:27+00:00

I was trying to wire up the jQuery Validator plugin to work with data

  • 0

I was trying to wire up the jQuery Validator plugin to work with data attributes instead of direct attributes (examples: data-minlength instead of minlength, data-equalTo instead of equalTo) so that my markup would validate as valid HTML5. Everything was working great until I got to data-equalTo. I ended up having to use data-equals instead and put a special condition in my code:

$("#form").validate();
['minlength', 'maxlength', 'range', 'min', 'max', 'equals' /* 'equalTo' no worky! */].forEach(function (item) {
    $('input[data-' + item + ']').each(function () {
        if ($(this).data(item)) {
            var rule = {};
            if (item == 'equals') /* special condition because 'equalTo' never makes it into this if block */
                rule['equalTo'] = $(this).data(item);
            else
                rule[item] = $(this).data(item);
            $(this).rules("add", rule);
        }
    });
});

The problem seemed to be with the $('input[data-' + item + ']') selector. For whatever reason it was not selecting for data-equalTo. Is it reserved, or unable to be selected via jQuery for some reason?


Now working based on Yoshi’s feedback:

['minlength', 'maxlength', 'range', 'min', 'max', 'equalTo'].forEach(function (item) {
    $('input[data-' + item + ']').each(function () {
        var lowerItem = item.toLowerCase();
        if ($(this).data(lowerItem)) {
            var rule = {};
            rule[item] = $(this).data(lowerItem);
            $(this).rules("add", rule);
        }
    });
});
  • 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-09T14:21:29+00:00Added an answer on June 9, 2026 at 2:21 pm

    Using jquery, you’ll have to access the data-attributes in lowercase. In your case:

    $(somelement).data('equalto');
    

    and if that is unwanted, try attr

    $(somelement).attr('data-equalTo');
    

    though, you’ll not get the auto-parsing from jquery in that case.


    demo: http://jsfiddle.net/BS6wy/1/

    <div id="foo" data-equalTo="42"></div>​
    
    <script>
      console.log(
        $('#foo').data('equalTo'), // undefined
        $('#foo').data('equalto'), // 42 (as number)
        $('#foo').attr('data-equalTo')  // "42" (as string)
      );​
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to wire up Spring Data JPA objects manually so that I can
Trying to make this jQuery filter that uses .find case-insensitive. For example, when the
So I'm trying to work out how to design my wire-frame. It is essentially
I am trying to create a plugin very that has similar usage to the
I'm trying to wire-up LinqToSql to be my data access layer and running into
I'm trying to reformat some data that I have that isn't playing well when
I am trying to wire up an AsyncController so that when a user clicks
I am trying to wire up and change event jQuery handler for a dropdown
I'm trying to wire up a CheckBox to handle an event when check/unchecked. If
I'm trying to wire up Windsor 3.0 to inject connection strings from my web.config

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.