Questions tagged [prop]

The prop() function was added in jQuery 1.6 library. It returns a property for the first element of the matched set.

The .prop() method gets the property value for only the first element in the matched set. It returns undefined for the value of a property that has not been set, or if the matched set has no elements. To get the value for each element individually, use a looping construct such as jQuery's .each() or .map() method.

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.

293 questions
2384
votes
18 answers

.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…
Naftali aka Neal
  • 138,754
  • 36
  • 231
  • 295
103
votes
4 answers

jQuery attr vs prop?

Now this isn't just another What's the difference question, I have done some tests(http://jsfiddle.net/ZC3Lf/) modifying the prop and attr of
​ with the output being: 1) prop Modification test Prop:…
Hailwood
  • 79,753
  • 103
  • 257
  • 412
89
votes
2 answers

Getting the User Agent with JavaScript

I'd like to get a script that can grab the user's user agent and prop it to an attribute. I'm making a website problems contact form and I usually need to know what browser the user is using. How can I detect the user agent string and prop it as the…
henryaaron
  • 5,648
  • 18
  • 54
  • 78
78
votes
3 answers

difference between prop() and attr() in jQuery and when to use attr() and prop()

I saw in some places .attr() is used in jQuery.In some places .prop() is used.But i searched in SO and google i am very confused .Please tell me the exact difference between these two and when to use them. I have seen the following links …
PSR
  • 36,137
  • 33
  • 104
  • 147
28
votes
1 answer

Should href be set with prop() or attr()?

If I want to change the href of a link dynamically, should I do so using prop() or attr()?
Francisc
  • 66,160
  • 57
  • 172
  • 264
28
votes
4 answers

Why jQuery 1.9+ attr() method not deprecated?

Can I, a jQuery1.9+ software developer, "deprecate" the use of the attr() method in my day-by-day work? As showed in many questions, .prop() vs .attr() (main) jQuery attr vs. prop, there are a list of props? jQuery attr vs prop? Migrating jQuery…
Peter Krauss
  • 11,340
  • 17
  • 129
  • 247
19
votes
5 answers

jQuery .prop("disabled", false) not working in Chrome

having problems with .prop("disabled", false) it's works fine in opera and firefox but IE and chrome i can't get it to work.. Actualy it's a invination form and im make send button like this
user994461
  • 495
  • 1
  • 4
  • 15
15
votes
7 answers

changing the img src with jquery

The html structure I have is something like:
9
votes
3 answers

What benefit do Props bring to actor creation in Akka?

Being new to Akka I need help in understanding in a simple way what the benefit of Props is. What is the problem on having common OO style object creation? What I know is that this follows the factory pattern where you send the class and the…
Arpan Patro
  • 133
  • 1
  • 7
8
votes
1 answer

Calling functions after state change occurs in reactjs

My question is this. I have two components. First component is an image cropper. Second component is the one that i should display the cropped image. The problem i'm facing is i can pass the cropped image to my second component but i have to press…
CraZyDroiD
  • 5,264
  • 21
  • 64
  • 138
8
votes
1 answer

jQuery .prop() returns undefined, while .attr() works as expected for data-*

I am simply trying to get a couple of properties from two elements. Getting the property value from the input element works as expected. The problem is with getting the property data-detail property from the button element. It returns undefined when…
Liran H
  • 5,181
  • 4
  • 30
  • 39
7
votes
1 answer

removeAttr("selected") and .attr('selected','selected') not working properly

I have two select fields in my form. The first one is single-select and the other is multiple-select. Now what I want to do is select options in the multiple-select with given data depending on the chosen option in the single-select. To do this I'm…
MrSmith
  • 241
  • 4
  • 20
6
votes
3 answers

How to initialize the react functional component state from props

I'm using React hooks for app state, I wondered about how to initialize the functional component state using props? The useState hook doc says something definitive like, const [count, setCount] = useState(0); I want to initialize that 0 value by…
Kiran Maniya
  • 5,637
  • 4
  • 34
  • 53
6
votes
1 answer

Warning: Unknown prop on <> tag. Remove this prop from the element

I'm new to react and i was learning subclasses from one of Lynda examples. I'm creating a new subcomponent class called aptList and using this.props.eachItem.ownerName to iterate through each index from the JSON file where ownerName is a property.…
Aswin
  • 443
  • 5
  • 14
6
votes
5 answers

Using jQuery .attr or .prop to set attribute value not working

I've created a button with attribute named 'loaded' and initial value of 'no'. Upon clicking the button I'm running some ajax and at the very end of it I'm trying to set the 'loaded' attribute to 'yes' so that the ajax is not ran again if the user…
mmvsbg
  • 3,362
  • 17
  • 46
  • 67
1
2 3
19 20