1

For example, the class attribute of HTML tag, unlike other attributes has a different name on Javascript, which is className.

Because of that, element.class = "XXX" won't update the class of an element.

Therefore, I want to know if there are any attributes other than class has this characteristics.

EDIT: I'm not talking about JSX, I'm literally talking about JavaScript. Reference: https://developer.mozilla.org/en-US/docs/Web/API/Element/className

Wong Jia Hau
  • 2,639
  • 2
  • 18
  • 30
  • You're asking the wrong question. Which HTML attributes are reflected as properties at all? And of these, you can fairly easily go through to find those where the names don't match. Notice that in the DOM, you can come up with arbitrary attribute names. – Bergi Jun 14 '20 at 15:45
  • Did anyone make a list? I doubt, but you can go through the reserved words [here](https://www.w3schools.com/JS/js_reserved.asp) and make note yourself :P – tHeSiD Jun 14 '20 at 15:49
  • 1
    @Bergi the question you mentioned does not answer my question at all, so please re-open this question – Wong Jia Hau Jun 14 '20 at 15:51
  • @Bergi What I'm looking for is an exhaustive list of HTML attributes that has different name on Javascript DOM. I think you just misunderstood the question – Wong Jia Hau Jun 14 '20 at 15:53
  • There is `.dataset` for `data-*` attributes, see https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes – NVRM Jun 14 '20 at 15:56
  • 2
    You guys are not answering my question all, nevermind I'll ask another one. – Wong Jia Hau Jun 14 '20 at 15:57
  • @WongJiaHau Asking for an exhaustive list is off-topic on SO. Closing as a dupe of the question that explains where the differences originate, where to expect similarities, and what terminology to use when searching for such a list, is the best thing to be done imo. – Bergi Jun 14 '20 at 16:00
  • @WongJiaHau I understood your question for what its worth, my logic was that class and classname are named as such because of keyword/reserved word conflict is what I thought. – tHeSiD Jun 14 '20 at 16:00
  • @tHeSiD you are not wrong in that regard, but can you guarantee that's the only problem that resulted in different names? – Wong Jia Hau Jun 14 '20 at 16:01
  • Can't guarantee but can't think of any other reason either! – tHeSiD Jun 14 '20 at 16:04
  • @tHeSiD the fact that you cannot think of any other reason (so am I) doesn't mean it's not possible to have another reason. – Wong Jia Hau Jun 14 '20 at 16:05
  • @WongJiaHau See `.value` vs `.defaultValue` for another case where names differ but the reason is not reserved words – Bergi Jun 14 '20 at 16:09
  • @tHeSiD Sorry dude, I might sound hostile but I think it's due to the lack of emojis :D – Wong Jia Hau Jun 14 '20 at 16:20

0 Answers0