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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:19:47+00:00 2026-05-26T02:19:47+00:00

I simply want to get the current value of a field’s attribute. This field

  • 0

I simply want to get the current value of a field’s attribute.

This field has a default value like:

<input validation="defaultValue" />

When i want to get the validation attribute, i don’t know if it has been updated before or if this is still the default value.

So the property get with prop() return undefined when the property is not set (not yet updated), and the attr() method return always the default value (that’s not true actually for maintainability but that will be in the future).

Is there a method that check:

if property is set => return property
else return attribute

Thanks

  • 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-26T02:19:47+00:00Added an answer on May 26, 2026 at 2:19 am

    This snippet will do:

    var input = $("input");
    var method = typeof input.prop("validation") != "undefined" ? "prop" : "attr";
    input[method]("validation");
    
    //Shortened to:
    var input = $("input");
    input[typeof input.prop("validation")!="undefined"?"prop":"attr"]("validation");
    

    Explanation:

    • If the property is not set typeof ... "undefined", the "prop" string returns. Otherwise, the "attr" string returns.
    • This string is used to select the right method of the input object, either input["prop"] (=input.prop) or input["attr"] (=input.attr).
    • Finally, the method is invoked, passing "validation" as an argument, resulting in:
      1. The property (if existent) or
      2. The attribute (if the property doesn’t exist).

    I recommend to use data-validation instead of validation, to be HTML5-compliant.

    Update: A JQuery method:

    (function($){
        /* Defines the curProp method - Getting the current property
         * When the property exists, the prop method is used. Otherwise: attr */
        $.fn.curProp = function(name){
            return this[typeof this.prop(name) == "undefined" ? "attr" : "prop"](name);
        }
    })(jQuery);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get the value currently selected and I simply want to alert
I have a simple dropdown and want to get the specific value of an
I simply want to send the current tab url to my extension: Following is
I know I can get the host name of the current page, by simply
i need to get the current value of a UISlider and put it into
Actually what I want to get is quite simple, I want to get the
I only want a simple Splash Screen Example. Get the Code, Insert my picture,
I want to save and store simple mail objects via serializing, but I get
I want to write Html format, but I can not even get a simple
I simply want to have an indeterminate JProgressBar animate in the bottom left corner

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.