with effect from jQuery 1.6 a new method has been introduced to change or retrieve values of attributes (or properties).
So what is the big deal here you might ask. the problem is that new comers doesn't understand the difference between the attr() method which has been there and the new method prop() which introduced lately.
In a HTML element there is two kind of things we can see.
In the above example id, value, name are belong to Attribute family while readonly is a property. So when to use attr() method or when to use prop() method is depend on whether you are dealing with an attribute or a property.
For example lets say you want to change the class attribute of above INPUT tag. Here you have to use attr() method like below.
But lets say if you want to make the above INPUT tag readable (it is readonly originally according to the code above). So here you have to use prop() from jQuery 1.6 onwards like below.
Yeah you might noticed the change. Before jQuery 1.6 you have to use attr() method like below.
But with new prop() you can save life by just giving a boolean as the second attribute.
So what is the big deal here you might ask. the problem is that new comers doesn't understand the difference between the attr() method which has been there and the new method prop() which introduced lately.
In a HTML element there is two kind of things we can see.
- Attributes
- Properties
<input id="q" value="" class="button-gray" name="_3_keywords" readonly>
In the above example id, value, name are belong to Attribute family while readonly is a property. So when to use attr() method or when to use prop() method is depend on whether you are dealing with an attribute or a property.
For example lets say you want to change the class attribute of above INPUT tag. Here you have to use attr() method like below.
$("#
q
").attr("class", "newclass")
But lets say if you want to make the above INPUT tag readable (it is readonly originally according to the code above). So here you have to use prop() from jQuery 1.6 onwards like below.
$("#
q
").prop("readonly", false)
Yeah you might noticed the change. Before jQuery 1.6 you have to use attr() method like below.
$("#
q
").attr("
readonly
", "
readonly
")
But with new prop() you can save life by just giving a boolean as the second attribute.
1) The jQuery prop() grabs the specified DOM property whereas attr() grabs the specified HTML attribute.
ReplyDelete2) The jQuery prop() method returns boolean value for selected, checked, readOnly, disabled and so on while attr() returns a defined string.
For details information look here:
http://www.namasteui.com/difference-between-prop-and-attr/
great
ReplyDeleteYou got an extremely helpful website I actually have been here reading for regarding an hour. I’m an initiate and your success is incredibly a lot of a concept on behalf of me.
ReplyDeletepython Training institute in Pune
python Training institute in Chennai
python Training institute in Bangalore
Well researched article and I appreciate this. The blog is subscribed and will see new topics soon.
ReplyDeleteData Science training in Chennai
Data science training in Bangalore
Data science training in pune
Data science online training
Data Science Interview questions and answers
Data science training in bangalore
I have to voice my sspaion for your kindness giving support to those people that should have guidance on this important matter
ReplyDeleteWeb designing training| Web Designing in chennai | web designing
DevOps Training| devops in chennai| devops training in chennai| best training institute in chennai
Best training in Blockchain in kk nagar chennai |Check Best Training @ Chennai in KK nagar, vadapalani in chennai |Blockchain institute in Chennai | Blockchain
Check Best Software Testing Training institute in KK nagar, Chennai | Software Courses| Real time Projects
And indeed, I’m just always astounded concerning the remarkable things served by you. Some four facts on this page are undeniably the most effective I’ve had.
ReplyDeleteData science Course Training in Chennai |Best Data Science Training Institute in Chennai
RPA Course Training in Chennai |Best RPA Training Institute in Chennai
AWS Course Training in Chennai |Best AWS Training Institute in Chennai
Devops Course Training in Chennai |Best Devops Training Institute in Chennai
Selenium Course Training in Chennai |Best Selenium Training Institute in Chennai
Java Course Training in Chennai | Best Java Training Institute in Chennai
I simply wanted to thank you so much again. I am not sure the things that I might have gone through without the type of hints revealed by you regarding that situation.
ReplyDeleteDevops Course Training in Chennai |Best Devops Training Institute in Chennai
Selenium Course Training in Chennai |Best Selenium Training Institute in Chennai
Java Course Training in Chennai | Best Java Training Institute in Chennai
Nice Blog. The Knowledge of this content very Clear and neatly presented.
ReplyDeleteData Science Training Course In Chennai | Data Science Training Course In Anna Nagar | Data Science Training Course In OMR | Data Science Training Course In Porur | Data Science Training Course In Tambaram | Data Science Training Course In Velachery
Nice post.Good information has been shared.
ReplyDeleteJava training in Chennai
Java training in Bangalore
Java training in Hyderabad
Java Training in Coimbatore
Java Online Training
I would like to thank you for the efforts you had made for writing this awesome article. This article inspired me to read more. keep it up.
ReplyDeleteCorrelation vs Covariance
Simple linear regression
data science interview questions
Your info is really amazing with impressive content..Excellent blog with informative concept. Really I feel happy to see this useful blog, Thanks for sharing such a amazing blog..
ReplyDeleteweb designing training in chennai
web designing training in tambaram
digital marketing training in chennai
digital marketing training in tambaram
rpa training in chennai
rpa training in tambaram
tally training in chennai
tally training in tambaram
ReplyDeleteI just see the post i am so happy the post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be subscribing to your feed and I hope you post again soon.
data science training in chennai
data science training in annanagar
android training in chennai
android training in annanagar
devops training in chennai
devops training in annanagar
artificial intelligence training in chennai
artificial intelligence training in annanagar
Wow, amazing weblog format! How lengthy have you been running a blog for? you make running a blog look easy. The total glance of your website is wonderful, let alone the content!
ReplyDeletedata science training in chennai
data science training in velachery
android training in chennai
android training in velachery
devops training in chennai
devops training in velachery
artificial intelligence training in chennai
artificial intelligence training in velachery
nice blog...
ReplyDeleteangular js training in chennai
angular js training in omr
full stack training in chennai
full stack training in omr
php training in chennai
php training in omr
photoshop training in chennai
photoshop training in omr
Thanks for Sharing This Article.It is very so much valuable content. I hope these Commenting lists will help to my website
ReplyDeletebest blockchain online training
ReplyDeleteThis post is so interactive and informative.keep update more information...
Advantages of Cyber Security
Importance of Cyber Security
Informative blog, nice content. Thanks for writing this blog.
ReplyDeleteBest Data Science Training in Hyderabad
I can set up my new idea from this post. It gives in depth information. Thanks for this valuable information for all,..
ReplyDeletedata analytics courses in hyderabad with placements
This post is so interactive and informative.keep update more information...
ReplyDeleteAndroid Training in Tambaram
Android Training in Chennai
Great post. keep sharing such a worthy information.
ReplyDeleteSwift Developer Course in Chennai
Swift Training in Bangalore
Swift Online Course
Great post. keep sharing such a worthy information.
ReplyDeleteData Science Certification in Chennai