Setting a Attribute without Value
See original GitHub issueI have a Attribute without a Value wich I’d like to set on a Element:
element.SetAttribute("readonly", null);
how can I do this?
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Set an Attribute Without a Value in JavaScript - Maker's Aid
The best ways to set an empty attribute to one or multiple DOM elements in your HTML markup, with plain JavaScript.
Read more >How to set attribute without value using jQuery
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, ...
Read more >How to declare an attribute in Python without a value
We can directly assign the attributes with the None value. By creating a class and initializing two variables within the class with None....
Read more >Element: setAttribute() method - Web APIs | MDN
Boolean attributes are considered to be true if they're present on the element at all. You should set value to the empty string...
Read more >JavaScript : Set attribute without value - YouTube
JavaScript : Set attribute without value [ Gift : Animated Search Engine : https://bit.ly/AnimSearch ] JavaScript : Set attribute without ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So answer to the question: There is no attribute “without” a value. Every attribute has a value.
is what you actually look for (at least that’s my opinion). The
readonly
(as an example) only cares about whether its available or not - not what value it has.Yeah, as I said: The behavior comes from the JS to native transition and the cast to a string. We do not have the JavaScript types and our instance is already a (null) string. So writing “null” would not make sense to me. If you plug in a scripting engine then yes - you get the same behavior as expected from JS.
Similarly, using some arbitrary object in JavaScript will result in its string representation (e.g.,
[object Object]
for a general one), but in C# you’ll get a type mismatch exception (if done via reflection; otherwise a compilation error occurs of course). So the exact JS behavior cannot be matched anyway.Long story short: My aim is not to copy the behavior tied to JS, but the right behavior (i.e., the behavior as defined from the W3C - which is independent of the used language).
Back to the topic: I agree - this is mostly about aesthetics and the serialization of the DOM. So I would say everything is as it should be.