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
5
votes
1 answer

React state array updates/renders entire array, is there a work-around?

Here's the basic idea... constructor(props) { super(props); this.state = { children: [{id:1},{id:2}], // HERE ARE THE TWO OBJECTS style: {top: 0} }; } Now let's say I update one of those two objects but those objects are…
jscul
  • 656
  • 1
  • 8
  • 18
5
votes
1 answer

Is there any situation where I must use .attr() over .prop()?

As far as I am aware, the .prop() function can do everything the .attr() function can do but in a generally safer and simpler way. For example: If I want to get the default state of a checkbox in the HTML, I can do…
dallin
  • 7,138
  • 1
  • 29
  • 36
5
votes
7 answers

jQuery .prop('checked', false) does not work

HTML:
Check Me!
JS: $(window).load(function() { var myFunc = function() { if($('#box').prop('checked', false)) { $('.form').append('

Checkbox is not…

uxcode
  • 365
  • 1
  • 3
  • 16
5
votes
1 answer

jQuery Upgrade, .attr and .prop - 1.2.6 to 1.9.1

I'm trying to upgrade a large number of sites at work from very old versions of jQuery (1.2.6, 1.4.3) to the latest version (1.9.1). Things are going pretty well - the Migration script does most of the legwork even though that's only for 1.6.4 to…
Joe
  • 15,062
  • 4
  • 38
  • 77
4
votes
3 answers

jQuery .prop() compatibility

I'm trying to test if the .prop() method exists on the current jQuery included (for compatibility reason) via: if(typeof $.prop === 'function') I would expect that the condition above is true for jQuery >= 1.6 and false for jQuery < 1.6 as I can…
Dalen
  • 8,346
  • 4
  • 44
  • 51
4
votes
3 answers

React replace componentWillReceiveProps

Having the following method in my child component which updates state on prop changes which works fine componentWillReceiveProps(nextProps) { // update original states this.setState({ fields: nextProps.fields, containerClass:…
fefe
  • 7,517
  • 20
  • 83
  • 158
4
votes
3 answers

React Native: Passing props between components and componentWillMount() method

I'm using React Native 0.43. I've two components, named ParentComponent and ChildComponent. I want to pass some props from parent to child component. I'm using following code (abridged version) in parent component: export default class…
Faisal Khurshid
  • 1,627
  • 3
  • 16
  • 25
4
votes
1 answer

Passing Additional Arguments with map() in React

I'm currently mapping over a prop like so: renderList(item) { return(
shows up
) } render() { return(
{this.props.items.map(this.renderList)}
lost9123193
  • 7,498
  • 18
  • 49
  • 87
4
votes
1 answer

Using jQuery's .prop method to set a property to a function

I am trying to assign a function to a property on bunch of elements using .prop() $('.whatever').prop({MyProp:MyFunc}); Looking closely at the documentation for this function it seems there is a special behaviour where the value is a function and…
DJL
  • 1,821
  • 3
  • 17
  • 31
4
votes
2 answers

jQuery attr vs. prop, there are a list of props?

This is not a duplicate question, I need only to decide if the better/fast/correct is to use attr or to use prop. The simplest and reliable way is checking into a list. A "list of element-name where the better is use prop(name) and/or a list where…
Peter Krauss
  • 11,340
  • 17
  • 129
  • 247
3
votes
1 answer

jQuery 1.6 prop() on div's title

Possible Duplicates: .prop() vs .attr() What is the differnece between doing $('div').prop('title','whatever'); //set $('div').prop('title'); //get and $('div').attr('title','whatever'); //set $('div').attr('title'); //get prop() seems to…
Pinkie
  • 9,492
  • 21
  • 76
  • 122
3
votes
2 answers

Vuejs Mutating Object passed as a prop

If I'm passing (a reference to) an Object as a prop is it OK to mutate values in the prop? I'm developing a web app which will require a lot of values to be passed to a component, and I'm trying to find the best way of passing the values to the…
Stiv
  • 63
  • 7
3
votes
1 answer

Passing PHP variable as prop to Vue tab component

I'm trying to pass the PHP variable $avail as a prop to my Vue component ComponentHome. Below is a simplified version of my code. On my page, the "avail" variable seems to be undefined, as the space after "Availability:" is blank. I have tried using…
Agirl
  • 45
  • 6
3
votes
0 answers

.attr() or .prop() or replaceWith Not Affecting href in iOS?

I am trying to figure out why the iOS Safari browser won't apply a href alteration, like it does on a desktop browser. So far, I have tried .attr() and .prop(), but neither one seems to apply the URL adjustment. To be more descriptive, I am trying…
nrweb
  • 191
  • 12
3
votes
2 answers

Using data from one component in another in Reactjs

I made a counting app that when you click you level and get gold, but how do use the data in another component? For example, I want to use this.state.max in another component. Sorry, I'm quite new to React import React, {Component} from…
malaika
  • 431
  • 1
  • 5
  • 15
1
2
3
19 20