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

  • Home
  • SEARCH
  • 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 4543044
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T15:28:33+00:00 2026-05-21T15:28:33+00:00

This doesn’t work: $(#elementId).attr(required, true); In both Chrome and Firefox, the DOM produces either

  • 0

This doesn’t work:

$("#elementId").attr("required", "true");

In both Chrome and Firefox, the DOM produces either required as the attribute (no value) or required="" (empty value).

And it doesn’t matter that the value in this example is “true”. If you try “asdf” the same thing happens.

What’s odd is that I believe this used to work because this new code is part of a large project that’s been ongoing for several years.

The only thing I can think of is that my Chrome (v10) and Firefox (v4) are now both sufficiently advanced that they’re recognizing the required attribute as an HTML5 reserved keyword. I added the novalidate attribute, thinking that that might turn off any form-related HTML5-ness. No such luck.

Thoughts?

Edit:

To clarify, this only happens with JQuery. If I say this, it works:

$("#elementId")[0].setAttribute("required", "true");

Is there a bug in JQuery? Any idea why this only happens with JQuery? Our development team likes all code to go through JQuery where possible. I can use the straight setAttribute JavaScript method, but would rather use a JQuery solution that works.

Edit 2:

The crux of the matter is this…

Why does using JQuery’s attr() method not work when the regular setAttribute() method does? Doesn’t the attr() method call setAttribute() at some point lower down?

That is what is so confusing. Chrome and Firefox are perfectly fine setting required="true" if you use setAttribute().

  • 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-21T15:28:34+00:00Added an answer on May 21, 2026 at 3:28 pm

    It is indeed browser related. I checked in IE8 and it will apply whatever string value you set to the required attribute.

    Since you don’t need any value (only the attribute must be present), this won’t affect default behavior. If you are abusing the attribute value for javascript hooks, that’s another thing 🙂

    <input required> is the same as <input required=""> and <input required="honky-tonk">

    Since IE8 doesn’t support html5, it’s just like setting a made-up attribute, so you could set $("input").attr("derp", "derty") and it would assign it to the element.

    My guess is that jquery uses the required="" for folks who wish to use this in XHTML strict syntax, while still conforming to HTML5 standards.

    http://dev.w3.org/html5/spec/Overview.html#the-required-attribute

    http://dev.w3.org/html5/spec/Overview.html#boolean-attribute

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

Sidebar

Related Questions

How come this doesn't work (operating on an empty select list <select id=requestTypes></select> $(function()
Can anybody tell my why this doesn't work in the Android emulator? From the
Why doesn't this Google Chart API URL render both data sets on this XY
Why doesn't this work (when parameter is set to 1) : SELECT * FROM
This doesn't work panel1.layout: layout [ offset: 0x0 yuml-image: image img ] panel2.layout: layout
This doesn't work. I've got an exception from SQL databse that column does not
Why this doesn't work? (For hell's sake!) template<class T> class A { typedef typename
Why this doesn't work in Firebug console: function(s,e) { setTimeout(function(){grvClosingDocs.Refresh();CBPDocFlow.PerformCallback();},100) } While this does:
I'm not sure why this doesn't work: scala> case class Loader(n: String, x: String,
Could someone tell me why this doesn't work? def selectAndCopy(x,y,z,w): ctypes.windll.user32.SetCursorPos(x,y) time.sleep(1) win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, 0,

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.