r/learnjavascript • u/Low_Mammoth_9371 • Feb 17 '23
How to control HTML element attributes using JS cheatsheet
9
u/ray_zhor Feb 17 '23
this is a great cheat sheet. the cheat sheet I'm looking for is what attributes can be accessed directly and which ones have to be accessed via set/getAttribute
5
u/Low_Mammoth_9371 Feb 17 '23
Thanks!
Yeah, this issue confused me at first when I started using shorthand. Doesn't work for custom attributes.
1
u/weenis-flaginus Feb 17 '23
Can you clarify the use of this? Attributes like what?
3
u/Low_Mammoth_9371 Feb 17 '23
Attributes on any HTML element, like class and data-src below:
<img class="img" data-src="url-to-image">Attributes are used for a wide variety of reasons, including styling, identifying elements, storing data, setting the source for a resource and more.
1
0
Feb 17 '23
[deleted]
4
u/Low_Mammoth_9371 Feb 17 '23
Sure, I created it using Cabron: https://carbon.now.sh/
I think there is an extension for VSC but not one that I have used personally.
11
u/Low_Mammoth_9371 Feb 17 '23 edited Feb 17 '23
Code as text: