12

Accessing DOM Elements in React

Sometimes you want to access properties and methods on an HTML element directly. In our React-colored world, where JSX represents everything that is good and pure about markup, why would you ever want to deal directly with the horribleness that is HTML? As you will find out (if you haven’t already), in many cases, dealing with HTML elements through the JavaScript DOM API directly is easier than fiddling with “the React way” of doing things. To highlight one such situation, take a look at the Colorizer example in Figure 12.1.

A figure shows a white square. A text box for entering a color value is present below the square along with a "go" button to its right.

Figure 12.1 Colorizer example.

If you have access to a browser, you can view it ...

Get Learning React: A Hands-On Guide to Building Web Applications Using React and Redux, Second edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.