Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre JSX Specifying Attributes | Getting Started: JSX
Introduction to React

bookJSX Specifying Attributes

In order to specify attributes to the elements we can use the syntax: <element attribute=value></element>

It is very similar to HTML though it is important to note that the names of attributes are sometimes different and follow camelCase convention.

For example class in JSX is className instead, and tabindex is tabIndex.

const webLink = <a href="https://codefinity.com/">Codefinity</a>

We can also assign dynamic attributes by embedding an expression:

const element = <img src={user.avatarUrl}></img>;

Note

We don't put quotes around curly braces when embedding a JavaScript expression in an attribute.

question mark

What is the correct way to specify the class attribute to a JSX element?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 4

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Suggested prompts:

Posez-moi des questions sur ce sujet

Résumer ce chapitre

Afficher des exemples du monde réel

Awesome!

Completion rate improved to 2.7

bookJSX Specifying Attributes

Glissez pour afficher le menu

In order to specify attributes to the elements we can use the syntax: <element attribute=value></element>

It is very similar to HTML though it is important to note that the names of attributes are sometimes different and follow camelCase convention.

For example class in JSX is className instead, and tabindex is tabIndex.

const webLink = <a href="https://codefinity.com/">Codefinity</a>

We can also assign dynamic attributes by embedding an expression:

const element = <img src={user.avatarUrl}></img>;

Note

We don't put quotes around curly braces when embedding a JavaScript expression in an attribute.

question mark

What is the correct way to specify the class attribute to a JSX element?

Select the correct answer

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 4
some-alt