Trending Prop Design Discussions

Follow

Ask the Community


Ask any professional question and get answers from other specialists.

Stream language
Muhammad Usman Usman's image
Question added by Muhammad Usman Usman Software Enginner Five Rivers Technologies
10 years ago

Which is better prop() or attr()?‎

$(selector).click(function(){ //instead of: this.getAttribute('style'); //do i use: $(this).prop('style'); //or: $(this).attr(‎ ... See More

Answers:
7
Followers:
Views:
300
Vote Count:
1
Answer should contain a minimum of 25 characters.
Default profile image  
Answer added by  Deleted user
10 years ago

so prop() is jquery1.6+ alternative for the .attr(), in terms of concept they do the same, but each is for a different version,we upgraded lately to jquery1.8 and found t ... See More

Mohammad Arif's image  
Answer added by  Mohammad Arif, Principal Engineer UI, NatWest Group
10 years ago

The difference between attributes and properties can be important in specific situations. Before jQuery1.6, the .attr() method sometimes took property values into account ... See More

Faizan Qureshi's image  
Answer added by  Faizan Qureshi, Principal Software Engineer, Naseeb Online Services
10 years ago

The link that Muhammad Majid Saleem provided explains a lot as far as the difference is concerned. I'll just like to add one advise to help you out incase such funct ... See More

Fadi Alkhateeb's image  
Answer added by  Fadi Alkhateeb, Senior Front End Developer, NexTwo
10 years ago

.attr() and .prop() are same, but .attr() was valid and used until jquery1.6+ then prop() comes as an alternative.

Munsif Mulla's image  
Answer added by  Munsif Mulla, Senior UI Engineer, FreeCharge
10 years ago

If you are trying to get the values then you should better go for "attr()" Even this can be used to set the values as well, Like if you want to set your valu ... See More

Muhammad Ahsan Mirza's image  
Answer added by  Muhammad Ahsan Mirza, Software Development Engineer, Remit Anywhere Solutions
10 years ago

.prop() as the name indicates refers to the properties while .attr() refers to an element's attributes. Both of them can be used interchangeably for most of the case ... See More

Muhammad Majid Saleem's image  
Answer added by  Muhammad Majid Saleem, Senior PHP Developer / Project Manager, SwaamTech
10 years ago

I found a very good reply over internet: http://stackoverflow.com/questions/5874652/prop-vs-attr