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
6
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
  • 8,755
  • 27
  • 104
  • 180
6
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
  • 153
  • 2
  • 9
6
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
  • 748
  • 1
  • 10
  • 25
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
  • 8,775
  • 2
  • 36
  • 41
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
  • 375
  • 1
  • 3
  • 17
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,669
  • 4
  • 48
  • 83
5
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
  • 13,174
  • 24
  • 167
  • 304
4
votes
1 answer

How dangerous is it to mutate a Vue prop by the child?

Vue allows to mutate props but it is not recommended. In the docs (https://vuejs.org/guide/components/props.html#one-way-data-flow) I found that As a best practice, you should avoid such mutations [mutating nested props by the child] unless the…
VeGoh5i
  • 51
  • 2
4
votes
2 answers

How can I call a Parent function from a React functional component?

I want my React functional component to call a function in its parent. I was able to do this with class components like so: But I'm having trouble access this.functionName withtin my child component, which is a…
AlwaysQuestioning
  • 1,464
  • 4
  • 24
  • 48
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,856
  • 4
  • 47
  • 52
4
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
  • 10,126
  • 22
  • 78
  • 124
4
votes
1 answer

React: Passing Props from grandparent to grandchild

I have a problem with passing props in react. This is my folder structure: src Component Button.js Container PageContainer.js Page Page.js I am using Bootstrap 4 to create a Button within Button.js:
yannistrom
  • 55
  • 1
  • 5
4
votes
2 answers

undefined is not an object (evaluating '_react.PropTypes.object')

Just created a new project using reac-native-init . Using "react": "16.0.0", "react-native": "0.51.0", Running the project from xcode i am getting the below errors Unhandled JS Exception: Module AppRegistry is not a registered callable module…
sumesh
  • 2,179
  • 2
  • 21
  • 37
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,869
  • 3
  • 21
  • 27
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
  • 10,460
  • 26
  • 73
  • 113
1
2
3
23 24