Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


.prop() vs .attr()


So jQuery 1.6 has the new function prop().

$(selector).click(function(){
    //instead of:
    this.getAttribute('style');
    //do i use:
    $(this).prop('style');
    //or:
    $(this).attr('style');
})
or in this case do they do the same thing?

And if I do have to switch to using prop(), all the old attr() calls will break if i switch to 1.6?

UPDATE

See this fiddle: http://jsfiddle.net/maniator/JpUF2/

The console logs the getAttribute as a string, and the attr as a string, but the prop as a CSSStyleDeclaration, Why? And how does that affect my coding in the future?

asked May 20, 2015 in JAVASCRIPT by rajesh
0 votes
22 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...