1

i some have custom property from code behind.

i add them using

 sender.Attributes.Add("TextLinkNo", sender.TextLinkNo)
        sender.Attributes.Add("TextHeader", sender.TextHeader)
        sender.Attributes.Add("TextDisplay", sender.TextDisplay)
        sender.Attributes.Add("FSize", sender.FSize)
        sender.Attributes.Add("iRotation", sender.iRotation)
        sender.Attributes.Add("PrintStatus", sender.PrintStatus)
        sender.Attributes.Add("Parameter", sender.Parameter)
        sender.Attributes.Add("SupportDEC", sender.SupportDEC)

html code

<span id="ctl00_ContentPlaceHolder1_LabelAttributes1_TabContainer1_TabPanel1_08" 
itextstyle="0" asign="0" supportdec="0" linetp="0" textlinkno="0" parameter="0" 
supportfontsize="False" class="draglabel ui-draggable ui-resizable" printstatus="7" 
spaceadjust="0" irotation="0" actc5="False" index="8" fieldformat="C1" ifontstyle="0" 
stringstatus="0" fsize="-1" ialign="0" textdisplay="Commodity Name" textheader="False" 
istartline="0" style="position: absolute; border-style: solid; border-width: 1px; left: 9px; top: 205px; width: 476px; height: 174px; background-color: rgb(255, 192, 203);" top="8" left="19">
Commodity Name
<div class="ui-resizable-handle ui-resizable-e" style="z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-s" style="z-index: 90;"></div><div class="ui-resizable-handle ui-resizable-se ui-icon ui-icon-gripsmall-diagonal-se" style="z-index: 90;"></div></span>

i can get these properties using

$(this).attr("supportdec");

but not

$(this).prop("supportdec");
$(this).prop("data-supportdec");

i tot prop is supported what attr supported +additional?

vbCoder
  • 75
  • 3
  • 12
  • so why cant you just use attr? – scald Jun 06 '14 at 02:45
  • i just want to know why prop not able to get the value. i use whatever it works. is just a general question.some said attr get something close but not actual value. prop is better over attr. but i find that prop always not able to get what i want – vbCoder Jun 06 '14 at 02:48
  • 1
    Take a look at [this answer](http://stackoverflow.com/a/5876747/543693) I believe it explains what you're asking in detail. From that answer: "An attribute value may only be a string whereas a property can be of any type. For example, the checked property is a Boolean, the style property is an object with individual properties for each style, the size property is a number." – Adam Merrifield Jun 06 '14 at 02:53
  • hi adam i read that artical too. but everywhere is using checked as example. so am i right to say that. for checked property. we use prop is better. and the rest use attr? – vbCoder Jun 06 '14 at 03:14
  • possible duplicate of [.prop() vs .attr()](http://stackoverflow.com/questions/5874652/prop-vs-attr) – brasofilo Jun 11 '14 at 20:48

1 Answers1

2

There have been numerous questions already asked which document the difference between .attr() and .prop().

I would recommend reading through this StackOverlfow post.

The difference is also documented in the jQuery api for the .prop() function, which is located here.

The following was pulled from the jQuery site mentioned above.

Attributes vs. Properties

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.

For example, selectedIndex, tagName, nodeName, nodeType, ownerDocument, defaultChecked, and defaultSelected should be retrieved and set with the .prop() method. Prior to jQuery 1.6, these properties were retrievable with the .attr() method, but this was not within the scope of attr. These do not have corresponding attributes and are only properties.

According to the W3C forms specification, the checked attribute is a boolean attribute, which means the corresponding property is true if the attribute is present at all—even if, for example, the attribute has no value or is set to empty string value or even "false". This is true of all boolean attributes.

Nevertheless, the most important concept to remember about the checked attribute is that it does not correspond to the checked property. The attribute actually corresponds to the defaultChecked property and should be used only to set the initial value of the checkbox. The checked attribute value does not change with the state of the checkbox, while the checked property does. Therefore, the cross-browser-compatible way to determine if a checkbox is checked is to use the property.

Community
  • 1
  • 1
Kevin
  • 2,752
  • 1
  • 24
  • 46