0

In my $().ready() area, I want to add a property to an object, based on another property of it. it should be done before any event on the object.

e.g:

<input value="text" />

$().ready(function(){
  $("input").newProp = ???
});

How can it be done?

yossi
  • 3,090
  • 7
  • 45
  • 65

1 Answers1

1

You just read off whatever property you want to use:

$(document).ready(function() {
    $("input").prop("newPropName", $("input").prop("propertyToCopy"))
});

If you want to add a property without use of $.prop(), then you would have to directly access the HTML element:

$("input")[0].newPropName = $("input")[0][propName];
Bic
  • 3,141
  • 18
  • 29
  • Thanks, but i don't want to add an attribute, just a property to the object. – yossi Sep 09 '14 at 15:19
  • That is a property. Adding an attribute would be done throught `$.attr`. – Bic Sep 09 '14 at 15:22
  • Oh ... seems like i got it wrong. thought that `prop` replaced `attr`, and `attr` was deprecated. You are correct. thanks! – yossi Sep 09 '14 at 15:26