Questions tagged [attributes]

The attributes tag should be used for any issues relating to a property of an object, element, or file, etc.

In computing, an attribute is a specification that defines a property of an object, element, or file. It may also refer to or set the specific value for a given instance of such.

For clarity, attributes should more correctly be considered metadata. An attribute is frequently and generally a property of a property.

However, in actual usage, the term attribute can and is often treated as equivalent to a property, depending on the technology being discussed.

An attribute of an object usually consists of a name and a value; of an element, a type or class name; of a file, a name and extension.

  • Each named attribute has an associated set of rules called operations: one doesn't sum characters or manipulate and process an integer array as an image object — one doesn't process text as type floating point (decimal numbers).
  • It follows that an object definition can be extended by imposing data typing: a representation format, a default value, and legal operations (rules) and restrictions ("Division by zero is not to be tolerated!") are all potentially involved in defining an attribute, or conversely, may be spoken of as attributes of that object's type. A JPEG file is not decoded by the same operations (however similar they may be—these are all graphics data formats) as a PNG or BMP file, nor is a floating point typed number operated upon by the rules applied to typed long integers.

See also:

13044 questions
131
votes
7 answers

Unable to set data attribute using jQuery Data() API

I've got the following field on an MVC view: @Html.TextBoxFor(model => model.Course.Title, new { data_helptext = "Old Text" }) In a seperate js file, I want to set the data-helptext attribute to a string value. Here's my…
Jason Evans
  • 28,906
  • 14
  • 90
  • 154
131
votes
9 answers

Can a C# class inherit attributes from its interface?

This would appear to imply "no". Which is unfortunate. [AttributeUsage(AttributeTargets.Interface | AttributeTargets.Class, AllowMultiple = true, Inherited = true)] public class CustomDescriptionAttribute : Attribute { public string Description…
Roger Lipscombe
  • 89,048
  • 55
  • 235
  • 380
131
votes
3 answers

How does inheritance work for Attributes?

What does the Inherited bool property on attributes refers to? Does it mean that if I define my class with an attribute AbcAtribute (that has Inherited = true), and if I inherit another class from that class, that the derived class will also have…
devoured elysium
  • 101,373
  • 131
  • 340
  • 557
125
votes
5 answers

ruby on rails f.select options with custom attributes

I have a form select statement, like this: = f.select :country_id, @countries.map{ |c| [c.name, c.id] } Which results in this code: ... ... But I want to add a custom HTML…
el_quick
  • 4,656
  • 11
  • 45
  • 53
123
votes
8 answers

Can I initialize a C# attribute with an array or other variable number of arguments?

Is it possible to create an attribute that can be initialized with a variable number of arguments? For example: [MyCustomAttribute(new int[3,4,5])] // this doesn't work public MyClass ...
billmn
122
votes
6 answers

How to create duplicate allowed attributes

I'm using a custom attribute inherited from an attribute class. I'm using it like this: [MyCustomAttribute("CONTROL")] [MyCustomAttribute("ALT")] [MyCustomAttribute("SHIFT")] [MyCustomAttribute("D")] public void setColor() { } But the "Duplicate…
ebattulga
  • 10,774
  • 20
  • 78
  • 116
119
votes
5 answers

How do I pass multiple attributes into an Angular.js attribute directive?

I have an attribute directive restricted as follows: restrict: "A" I need to pass in two attributes; a number and a function/callback, accessing them within the directive using the attrs object. If the directive was an element directive,…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
118
votes
2 answers

JavaScript: Listen for attribute change?

Is it possible in JavaScript to listen for a change of attribute value? For example: var element=document.querySelector('…'); element.addEventListener( ? ,doit,false); element.setAttribute('something','whatever'); function doit() { } I would…
Manngo
  • 14,066
  • 10
  • 88
  • 110
118
votes
8 answers

How to remove "onclick" with JQuery?

PHP code: Qualify I want to remove the onclick="check($id,1) so the link cannot be clicked or "check($id,1) won't be fired. How can I do it with JQuery?
Steven
  • 24,410
  • 42
  • 108
  • 130
116
votes
15 answers

Make HTML5 video poster be same size as video itself

Does anyone know how to resize the HTML5 video poster such that it fits the exact dimensions of the video itself? here's a jsfiddle which shows the problem: http://jsfiddle.net/zPacg/7/ here's that code: HTML:
115
votes
4 answers

Attribute to Skip over a Method while Stepping in Debug Mode

Is there an attribute I can use on a method so that when stepping through some code in Debug mode the Debugger stays on the outside of the method?
BuddyJoe
  • 69,735
  • 114
  • 291
  • 466
112
votes
13 answers

Get an object properties list in Objective-C

How can I get a list (in the form of an NSArray or NSDictionary) of a given object properties in Objective-C? Imagine the following scenario: I have defined a parent class which just extends NSObject, that holds an NSString, a BOOL and an NSData…
boliva
  • 5,604
  • 6
  • 37
  • 39
112
votes
4 answers

Sum / Average an attribute of a list of objects

Lets say I have class C which has attribute a. What is the best way to get the sum of a from a list of C in Python? I've tried the following code, but I know that's not the right way to do it: for c in c_list: total += c.a
jsj
  • 9,019
  • 17
  • 58
  • 103
111
votes
6 answers

How to loop over a Class attributes in Java?

How can I loop over a class attributes in java dynamically. For eg : public class MyClass{ private type1 att1; private type2 att2; ... public void function(){ for(var in MyClass.Attributes){ …
Zakaria
  • 1,675
  • 4
  • 21
  • 23
109
votes
3 answers

CSS values using HTML5 data attribute

width: attr(data-width); I want to know if there's any way it's possible to set a css value using HTML5's data- attribute the same way that you can set css content. Currently it doesn't work. HTML
CSS div { width:…
James Kyle
  • 4,138
  • 4
  • 28
  • 41