Questions tagged [attributes]

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

Filter by
Sorted by
Tagged with
2439 votes
16 answers
1.5m views

How to check if an object has an attribute?

How do I check if an object has some attribute? For example: >>> a = SomeClass() >>> a.property Traceback (most recent call last): File "<stdin>", line 1, in <...
Lucas Gabriel Sánchez's user avatar
1381 votes
8 answers
773k views

What is the purpose of the "role" attribute in HTML?

I keep seeing role attributes in some people's work. I use it too, but I'm not sure about its effect. For example: <header id="header" role="banner"> Header stuff in here ...
jeroen's user avatar
  • 13.9k
947 votes
7 answers
228k views

What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?

There are three assembly version attributes. What are differences? Is it ok if I use AssemblyVersion and ignore the rest? MSDN says: AssemblyVersion: Specifies the version of the assembly being ...
Jakub Šturc's user avatar
  • 35.5k
898 votes
21 answers
544k views

Difference between id and name attributes in HTML

What is the difference between the id and name attributes? They both seem to serve the same purpose of providing an identifier. I would like to know (specifically with regards to HTML forms) whether ...
yogibear's user avatar
  • 14.7k
546 votes
5 answers
333k views

Why use Ruby's attr_accessor, attr_reader and attr_writer?

Ruby has this handy and convenient way to share instance variables by using keys like attr_accessor :var attr_reader :var attr_writer :var Why would I choose attr_reader or attr_writer if I could ...
Saturn's user avatar
  • 18k
509 votes
21 answers
771k views

Python dictionary from an object's fields

Do you know if there is a built-in function to build a dictionary from an arbitrary object? I'd like to do something like this: >>> class Foo: ... bar = 'hello' ... baz = 'world' ... ...
Julio César's user avatar
  • 13.1k
453 votes
4 answers
284k views

Specify multiple attribute selectors in CSS

What is the syntax for doing something like: input[name="Sex" AND value="M"] Basically, I want to select the input element that has the attribute name="Sex" as well as the attribute value="M": <...
learningtech's user avatar
439 votes
18 answers
574k views

How can I create an object and add attributes to it?

I want to create a dynamic object in Python and then add attributes to it. This didn't work: obj = object() obj.somefield = "somevalue" AttributeError: 'object' object has no attribute '...
John's user avatar
  • 21.4k
424 votes
34 answers
359k views

Accessing dict keys like an attribute?

I find it more convenient to access dict keys as obj.foo instead of obj['foo'], so I wrote this snippet: class AttributeDict(dict): def __getattr__(self, attr): return self[attr] def ...
Izz ad-Din Ruhulessin's user avatar
356 votes
1 answer
19k views

List view getListItemXmlAttributes method fails with child publication items

I have created a JS class to populate SG/Folder list view data, when items are modified. (As per Jaime's approach) Everything works great when I operate on items in the publication they're created in. ...
Warner Soditus's user avatar
355 votes
2 answers
489k views

correct way to define class variables in Python [duplicate]

I noticed that in Python, people initialize their class attributes in two different ways. The first way is like this: class MyClass: __element1 = 123 __element2 = "this is Africa" def ...
jeanc's user avatar
  • 4,673
336 votes
22 answers
409k views

private final static attribute vs private final attribute

In Java, what's the difference between: private final static int NUMBER = 10; and private final int NUMBER = 10; Both are private and final, the difference is the static attribute. What's better? ...
user avatar
335 votes
5 answers
274k views

How do I remove the "extended attributes" on a file in Mac OS X?

I have an AppleScript script that runs a stress test. Part of the test is to open, save, and close certain files. Somehow, the files have picked up some "extended attributes" that prohibit the files ...
tames's user avatar
  • 3,359
315 votes
14 answers
155k views

When to use setAttribute vs .attribute= in JavaScript?

Has a best-practice around using setAttribute instead of the dot (.) attribute notation been developed? E.g.: myObj.setAttribute("className", "nameOfClass"); myObj.setAttribute("id", "someID"); or ...
Francisc's user avatar
  • 79k
295 votes
3 answers
176k views

How to access (get or set) object attribute given string corresponding to name of that attribute

How do you set/get the values of attributes of t given by x? class Test: def __init__(self): self.attr1 = 1 self.attr2 = 2 t = Test() x = "attr1"
Nullpoet's user avatar
  • 11.1k
272 votes
5 answers
299k views

How do you programmatically set an attribute?

Suppose I have a python object x and a string s, how do I set the attribute s on x? So: >>> x = SomeObject() >>> attr = 'myAttr' >>> # magic goes here >>> x.myAttr ...
Nick's user avatar
  • 21.9k
270 votes
7 answers
500k views

How to change an element's title attribute using jQuery

I have an form input element and want to change its title attribute. This has to be easy as pie, but for some reason I cannot find how to do this. How is this done, and where and how should I be ...
Brian's user avatar
  • 8,227
259 votes
7 answers
167k views

Set attribute without value

How do I set a data attribute without adding a value in jQuery? I want this: <body data-body> I tried: $('body').attr('data-body'); // this is a getter, not working $('body').attr('data-body',...
David Hellsing's user avatar
254 votes
6 answers
263k views

Get Enum from Description attribute [duplicate]

Possible Duplicate: Finding an enum value by its Description Attribute I have a generic extension method which gets the Description attribute from an Enum: enum Animal { [Description("")] ...
fearofawhackplanet's user avatar
253 votes
17 answers
261k views

Select elements by attribute

I have a collection of checkboxes with generated ids and some of them have an extra attribute. Is it possible to use JQuery to check if an element has a specific attribute? For example, can I verify ...
Ciprian Grosu's user avatar
252 votes
1 answer
171k views

What’s the purpose of the HTML "nonce" attribute for script and style elements?

W3C says there is a new attribute in HTML5.1 called nonce for style and script that can be used by the Content Security Policy of a website. I googled about it but finally didn't get it what actually ...
ata's user avatar
  • 3,516
251 votes
7 answers
326k views

Iterate over object attributes in python [duplicate]

I have a python object with several attributes and methods. I want to iterate over object attributes. class my_python_obj(object): attr1='a' attr2='b' attr3='c' def method1(self, ...
Pablo Mescher's user avatar
245 votes
8 answers
185k views

Python function attributes - uses and abuses [closed]

Not many are aware of this feature, but Python's functions (and methods) can have attributes. Behold: >>> def foo(x): ... pass ... >>> foo.score = 10 >>> dir(foo) [...
Eli Bendersky's user avatar
244 votes
6 answers
51k views

What is the point of noreturn?

[dcl.attr.noreturn] provides the following example: [[ noreturn ]] void f() { throw "error"; // OK } but I do not understand what is the point of [[noreturn]], because the return type of the ...
BЈовић's user avatar
  • 63.4k
233 votes
8 answers
88k views

What's the difference between a Python "property" and "attribute"?

I am generally confused about the difference between a "property" and an "attribute", and I can't find a great resource to concisely detail the differences.
Carson's user avatar
  • 17.5k
216 votes
10 answers
449k views

Extracting an attribute value with beautifulsoup

I am trying to extract the content of a single "value" attribute in a specific "input" tag on a webpage. I use the following code: import urllib f = urllib.urlopen("http://58....
Barnabe's user avatar
  • 2,285
201 votes
21 answers
538k views

Getting attributes of a class

I want to get the attributes of a class, say: class MyClass(): a = "12" b = "34" def myfunc(self): return self.a using MyClass.__dict__ gives me a list of attributes and functions, and ...
Mohamed Khamis's user avatar
193 votes
20 answers
347k views

Get all Attributes from a HTML element with Javascript/jQuery

I want to put all attributes in a Html element into an array: like i have a jQuery Object, whichs html looks like this: <span name="test" message="test2"></span> now one way is to use ...
k0ni's user avatar
  • 2,427
185 votes
5 answers
282k views

Are complex expressions possible in ng-hide / ng-show?

I want to do so: ng-hide="!globals.isAdmin && mapping.is_default" but the expression evaluates always to false. I do not want to define special function on $scope.
Paul's user avatar
  • 26.2k
176 votes
9 answers
119k views

How enumerate all classes with custom class attribute?

Question based on MSDN example. Let's say we have some C# classes with HelpAttribute in standalone desktop application. Is it possible to enumerate all classes with such attribute? Does it make sense ...
tomash's user avatar
  • 12.9k
174 votes
3 answers
57k views

Why "decimal" is not a valid attribute parameter type?

It is really unbelievable but real. This code will not work: [AttributeUsage(AttributeTargets.Property|AttributeTargets.Field)] public class Range : Attribute { public decimal Max { get; set; } ...
Cheng Chen's user avatar
  • 43.2k
172 votes
11 answers
159k views

Get list of data-* attributes using javascript / jQuery

Given an arbitrary HTML element with zero or more data-* attributes, how can one retrieve a list of key-value pairs for the data. E.g. given this: <div id='prod' data-id='10' data-cat='toy' data-...
Shawn Chin's user avatar
  • 85.6k
171 votes
1 answer
246k views

Getting the value of an attribute in XML

How would one get the value of attribute1 (blah) in the following xml using xslt: <name attribute1="blah" attribute2="blahblah"> </name>
Smern's user avatar
  • 18.9k
168 votes
8 answers
56k views

What are the best practices for using Assembly Attributes?

I have a solution with multiple project. I am trying to optimize AssemblyInfo.cs files by linking one solution wide assembly info file. What are the best practices for doing this? Which attributes ...
Jakub Šturc's user avatar
  • 35.5k
163 votes
11 answers
94k views

How to Compare Flags in C#?

I have a flag enum below. [Flags] public enum FlagTest { None = 0x0, Flag1 = 0x1, Flag2 = 0x2, Flag3 = 0x4 } I cannot make the if statement evaluate to true. FlagTest testItem = ...
David Basarab's user avatar
160 votes
5 answers
76k views

What is the difference between class and instance attributes?

Is there any meaningful distinction between: class A(object): foo = 5 # some default value vs. class B(object): def __init__(self, foo=5): self.foo = foo If you're creating a lot ...
Dan Homerick's user avatar
  • 4,178
156 votes
6 answers
334k views

javascript remove "disabled" attribute from html input

How can I remove the "disabled" attribute from an HTML input using javascript? <input id="edit" disabled> at onClick I want my input tag to not consist of "disabled" attribute.
Sam San's user avatar
  • 6,751
154 votes
10 answers
114k views

Can attributes be added dynamically in C#?

Is it possible to add attributes at runtime or to change the value of an attribute at runtime?
Jon Turner's user avatar
  • 2,962
153 votes
7 answers
513k views

Define an <img>'s src attribute in CSS [duplicate]

I need to define an <img>'s src attribute in CSS. Is there a way to specify this attribute?
Massimo Ugues's user avatar
151 votes
8 answers
234k views

Get all attributes of an element using jQuery

I am trying to go through an element and get all the attributes of that element to output them, for example an tag may have 3 or more attributes, unknown to me and I need to get the names and values ...
Styphon's user avatar
  • 10.4k
143 votes
11 answers
59k views

Custom Compiler Warnings

When using the ObsoleteAtribute in .Net it gives you compiler warnings telling you that the object/method/property is obsolete and somthing else should be used. I'm currently working on a project that ...
Micah's user avatar
  • 114k
141 votes
8 answers
138k views

Set attributes from dictionary in python

Is it possible to create an object from a dictionary in python in such a way that each key is an attribute of that object? Something like this: d = { 'name': 'Oscar', 'lastName': 'Reyes', 'age':32 }...
OscarRyz's user avatar
  • 198k
141 votes
4 answers
99k views

Test if a class has an attribute?

I'm trying to do a little Test-First development, and I'm trying to verify that my classes are marked with an attribute: [SubControllerActionToViewDataAttribute] public class ScheduleController : ...
JoshRivers's user avatar
  • 10.2k
139 votes
16 answers
107k views

NUnit Test Run Order

By default nunit tests run alphabetically. Does anyone know of any way to set the execution order? Does an attribute exist for this?
Riain McAtamney's user avatar
137 votes
3 answers
67k views

XML Serialization - Disable rendering root element of array

Can I somehow disable rendering of root element of collection? This class with serialization attributes: [XmlRoot(ElementName="SHOPITEM", Namespace="")] public class ShopItem { ...
Jan Remunda's user avatar
  • 7,880
134 votes
11 answers
98k views

Localization of DisplayNameAttribute

I am looking for a way to localize properties names displayed in a PropertyGrid. The property's name may be "overriden" using the DisplayNameAttribute attribute. Unfortunately attributes can not have ...
PowerKiKi's user avatar
  • 4,618
134 votes
3 answers
74k views

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 ...
devoured elysium's user avatar
132 votes
3 answers
109k views

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('...
Manngo's user avatar
  • 15.3k
132 votes
9 answers
83k views

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 ...
Roger Lipscombe's user avatar
131 votes
7 answers
134k views

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" })</span> In a seperate js file, I want to set the data-helptext ...
Jason Evans's user avatar
  • 29.1k

1
2 3 4 5
263