I have got a CSS class like so:
.simpleClass {
width: 25px;
}
And I have a matching element:
<div class="simpleClass"></div>
Can I add the property display: none;
to the CSS class .simpleClass
dynamically through jQuery? Thanks.
We will add the Language property. // Add properties dynamically to expando AddProperty(expando, "Language", "English"); The AddProperty method takes advantage of the support that ExpandoObject has for IDictionary<string, object> and allows us to add properties using values we determine at runtime.
You can use extension methods to extend a class or interface, but not to override them. An extension method with the same name and signature as an interface or class method will never be called. At compile time, extension methods always have lower priority than instance methods defined in the type itself.
Properties do not name the storage locations. Instead, they have accessors that read, write, or compute their values. For example, let us have a class named Student, with private fields for age, name, and code.
The alternative is using standard inheritance or composition to extend the class, which you already mentioned. Use a separate hash table to add properties to objects you don't control, and use your own access functions to wrap whatever behavior you want to appear to be uniform with respect to your added properties.
We can add properties to our class using the following syntax: In our example above, we've defined two propertyproperties of type string , one named FirstName , the other named LastName .
Show activity on this post. Use a separate hash table to add properties to objects you don't control, and use your own access functions to wrap whatever behavior you want to appear to be uniform with respect to your added properties.
Properties allow us to add state to our class. State can be anything which needs to be stored by an instance of your class. We can add properties to our class using the following syntax: In our example above, we've defined two propertyproperties of type string , one named FirstName , the other named LastName .
you can specify the style of the element by using .css
like
$("div.simpleClass").css("width","25px");
have a look at jQuery.css()
If I get it right, You don't want to give property to the instance element of simpleClass
, but would like to give an extra property to the whole class ( covering all instances ) using JS.
In this case, You can use jQuery to append a style element to the head, giving You the opportunity to add additional CSS declarations.
However, I would not recommend this, because it causes Your code, and structure to get messy.
$("head").append("<style> .simpleClass{ display:none; } </style>");
This snippet will give extra display:none
property to all .simpleClass
elements existing in the time of doing this, and will also affect every later-inserted .simpleClass
elements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With