Change text font style using button click in React
P粉127901279
P粉127901279 2023-08-29 00:02:49
0
1
479

const textBold =()=>{ const bold_text=document.getElementsByClassName('.form-control'); bold_text.style.fontStyle = "italic"; setText(bold_text) }

After clicking the button, the browser will jump to a blank page.

P粉127901279
P粉127901279

reply all (1)
P粉895187266

Since you are using thegetElementsByClassNamemethod, it will return an array/collection containing the elements of the given class.

If you only have one element, use.querySelectorinstead.

Alternatively, if you prefer to use thegetElementsByClassNamemethod, you can use a for loop or the.find()method to find the desired element and apply the style.

In React, I think usingrefis better than using the DOM API to locate elements.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!