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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:00:02+00:00 2026-06-12T05:00:02+00:00

I have a very simple example jsfiddle : HTML: <input type=text/> <input type=text value=aaa/>

  • 0

I have a very simple example jsfiddle:

HTML:

<input type="text"/>
<input type="text" value="aaa"/>

JS:

$("input:first").val("aaa");
alert($("input[value='aaa']").length);​

Why Chrome and IE returns different results? Why jQuery in Chrome not recognize the “value” when it was set using jQuery?
How I can solve it? I need that Chrome will return exactly the same result as IE.

EDIT: I unaccepted my answer, because after thinking about it little bit, I still not understand some things (maybe I am wrong regarding several parts):

1) As I know, the text displayed in textbox by browser, should always be in “value” attribute, because if I submit the form, the “values” displayed in textboxes and other input fields are submitted to server (if they are not disabled).

2) So if displayed text in textbox should be stored in “value” in order to be submitted, then it’s natural for me if $("input[type='text']").val("aaa") would assign the text “aaa” to “value” attribute, because it may be submitted later. If so, why $("input[value='aaa']") not pick it up?

3) Some other thing….when I not use “val” method of jQuery, and instead type the text directly to textbox, then it not goes to “value” attribute to? I made another example, where I not use “val” to assign text to textbox. I type it directly in textbox, and then $("input[value='aaa']") not pick it up again.

It’s very very strange for me…i understand the difference between the properties and attributes, but due to nature of HTML forms, I not understand why “val” not assigns the value to attribute, and when typing in directly, it not goes to “value” attribute to.

Updated jsfiddle

BTW: In http://blog.jquery.com/2011/05/12/jquery-1-6-1-released/ i found the following:

Neither .attr() nor .prop() should be used for getting/setting value.
Use the .val() method instead (although using .attr(“value”,
“somevalue”) will continue to work, as it did before 1.6).

They say that “val” should set the attribute…or my English not allows me to understand it right?

Please explain me 🙂

  • 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-12T05:00:04+00:00Added an answer on June 12, 2026 at 5:00 am

    I think it is because .val sets the property on the input. Then using the [value="aaa"] is looking at the attributes of the input, which hadn’t actually changed. If you change how you use jQuery to set the value of the input to:

    $("input:first").attr("value", "aaa");

    And then check the length, you’ll get the results you’re expecting.

    Fiddle: http://jsfiddle.net/gromer/ZnbpE/

    Difference between properties and attributes:
    http://blog.jquery.com/2011/05/12/jquery-1-6-1-released

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

Sidebar

Related Questions

I have a very simple example of a menu here: <ul id=1> <li><a href=#>First</a></li>
I have a very simple D3 example that first reads data into an associative
Here is a very simple example of what I have: http://jsfiddle.net/MxKLU/ Click on the
I have a very simple example that is not working. jsfiddle: http://jsfiddle.net/ThomasDeutsch/8hzhp/3/ // My
I have a very simple example. A button on the bottom of the screen
I have this very simple example that I am using to learn structs in
I have very simple OpenGL ES example similar to Hehe's example : http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/ As
I have very simple piece of code. The goal is when i input four-digit
Does anyone have a very simple example of how to overload the compound assignment
I have a query: (using a very simple example) SELECT ItemCategory, ItemID, Sales FROM

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.