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
11 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
11 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
11 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
11 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
11 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
11 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
11 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
11 years ago

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