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.

347 questions
2485
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
  • 144,921
  • 39
  • 244
  • 303
104
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
  • 89,623
  • 107
  • 270
  • 423
100
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
  • 6,042
  • 20
  • 61
  • 80
84
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 jQuery attr…
PSR
  • 39,804
  • 41
  • 111
  • 151
32
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
  • 77,430
  • 63
  • 180
  • 276
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
  • 13,174
  • 24
  • 167
  • 304
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
  • 510
  • 1
  • 5
  • 17
15
votes
7 answers

changing the img src with jquery

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

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
  • 6,622
  • 30
  • 95
  • 182
10
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
  • 153
  • 2
  • 8
8
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
  • 370
  • 4
  • 22
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
  • 9,143
  • 7
  • 39
  • 52
7
votes
2 answers

How to pass functions as props in Qwik JS?

Problem In React, we can pass functions as props into a child component when a function requires access to a state within the parent component of the aforementioned child. I was writing code for an application where I need such behavior to be…
7
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
  • 493
  • 7
  • 14
7
votes
5 answers

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

I've created a button with an 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 run again if the…
mmvsbg
  • 3,570
  • 17
  • 52
  • 73
1
2 3
23 24