skip to Main Content

I have a div which contain row-id=”
this row-id dynamically changes

so I want to give it background color

It is a react.js project. and i want to achieve this in jsx file.

I want something like-

from DOM get element with row-id=’someId’, and give it background color


I have a DOM rendered. It contains many divs, spans etc
Now on click of a button I want to select a div with attribute row-id=’abc’
and change its background color to gray

2

Answers


  1. Chosen as BEST ANSWER

    I achieved it using

    const targetElement: any = document.querySelector(`[row-id='${id}']`);
    targetElement.classList.add('idClass');
    

  2. you can create function in which that we can add the colour change condition and then will call the function where it would be needed.

    Can you share sample code , it will be useful to answer your question.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search