2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Define an HTML Class in JSX
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Define an HTML Class in JSX
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
- HTML and JSX may seem that they are exactly the same but there are a few differences between them.
|
|
|
|
- One of these differences is the naming convention.
|
|
|
|
- HTML attributes and event references in JSX become camelCase(onclick => onClick).
|
|
|
|
- There may also be some words reserved in JavaScript.For instance the word "class" cant be use to define HTML classes
|
|
|
|
in JSX.Therefore instead of using "class" you can use "className".
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
### Hint 1
|
2018-10-12 15:37:13 -04:00
|
|
|
- You may want to change "class" to "className".
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
|
|
|
|
2018-10-12 15:37:13 -04:00
|
|
|
```javascript
|
|
|
|
const JSX = (
|
2019-07-24 00:59:27 -07:00
|
|
|
<div className='myDiv'>
|
2018-10-12 15:37:13 -04:00
|
|
|
<h1>Add a class to this div</h1>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
```
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|