Forum Discussion

JoshuaThian's avatar
JoshuaThian
Community Member
2 days ago

Change a text color using javascript GSAP

Hi,

I'm looking to change a text color using javascript GSAP.

I tried the following code:

let gemba = document.querySelector("[data-acc-text='Gemba']");

gsap.to(gemba, {duration:2, fill:'#8d3dae'});

 

It doesn't work. I think it because my accessibility text 'Gemba' is the name of the text box and not the text itself?

If i change 'fill' to 'backgroundColor', it changes the textbox color. But i want to change the text color.

 

Any help is appreciated.

 

Thank you.

Joshua

  • Try this:

    let gemba = document.querySelector("[data-acc-text='Gemba'] text");
    gsap.to(gemba, {duration:2, fill:'#8d3dae'});

     

  • Nedim's avatar
    Nedim
    Community Member

    Try this:

    let gemba = document.querySelector("[data-acc-text='Gemba'] text");
    gsap.to(gemba, {duration:2, fill:'#8d3dae'});