Click here to Skip to main content
15,070,613 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
here is my HTML tag

<input id="textbox1" type="text" text="12345" value="xyz">

i need 12345, value of text attribute.

What I have tried:

i tried this $("#textbox1").prop('text');

Its giving undefined
Posted
Updated 10-Aug-16 23:00pm

1 solution

use .attr()[^]

JavaScript
var text = $('#textbox1').attr('text');
          alert(text);



From official site:
The difference between attributes and properties can be important in specific situations. Before jQuery 1.6, the .attr() method sometimes took property values into account when retrieving some attributes, which could cause inconsistent behavior. As of jQuery 1.6, the .prop() method provides a way to explicitly retrieve property values, while .attr() retrieves attributes.
   
v2
Comments
IamWsk 11-Aug-16 5:05am
   
Thanks for your prompt reply.
but i think attr is deprecated after jquery 1.6.@Karthik
Karthik_Mahalingam 11-Aug-16 5:09am
   
welcome :)
yes, it is
IamWsk 11-Aug-16 5:09am
   
Ok thanks before I was using attr only but after upgrading jquery I replaced all attr to prop coz in checkbox it was not working while checking "checked" attribute of the checkbox so i replaced attr to prop
Karthik_Mahalingam 11-Aug-16 5:12am
   
go through these links and explore the difference
.prop() | jQuery API Documentation[^]
.attr() | jQuery API Documentation[^]
IamWsk 11-Aug-16 5:15am
   
Ok I understood and I will make sure before using attr and prop.
Thanks 1s again.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900