Issues with changing the color of specific words in a paragraph

Topic summary

A user is experiencing issues with changing specific words to red color across multiple sections of their website. Their JavaScript code works correctly for a single section but fails when attempting to apply the same styling to additional sections—reverting all text back to white.

Current approach:

  • Uses setInterval to repeatedly query and modify paragraph innerHTML
  • Wraps target words in <span style="color:red"> tags
  • Targets sections by specific Shopify section IDs

The problem:
When adding a second section (ID ending in ...484-122ca484...) to the existing code, the color changes stop working entirely for both sections.

Code snippet provided shows the working single-section implementation with conditional logic for mobile viewports (width < 756px).

A responder asks for clarification about which specific paragraph needs color changes and suggests trying a CSS-based solution instead of JavaScript. The discussion remains open with no resolution yet—awaiting the original poster’s response about requirements for the additional section.

Summarized with AI on November 14. AI used: claude-sonnet-4-5-20250929.

Hey

Lately ive been trying to turn certain words in my sections to a red color. Now when I tried using a code for just 1 section, it worked just fine, but now I’m having issues with including other sections as well. As soon as I include it, everything goes back to normal white color.

Here is the code I used for a single section which worked:

setInterval(()=> {
    changeColor()
}, 10)
function changeColor () {
    let paragraph = document.querySelector("#shopify-section-66f0799f-7a42-4714-84ff-d2b2d04e948c > div > div > div > div.rich-text__text.featured_text");
    if(!paragraph) return;
    if(window.innerWidth < 756){
        paragraph.innerHTML = `<p>Alright, so the issue with most fitness services nowadays is that they simply look way too bland and don't have that <span style="color:red">INSPIRING</span> feel to it.</p><p>Seems like everyone is focusing way too much on selling you some mediocre ''gain muscle fast'' scheme that ends up benefiting you for a few months before ultimately going back to square one.</p><p>Now of course UEX offers you exclusive workouts you never tried before, customized meal plans, fast and <span style="color: red">modernized</span> database and many other amazing features,</p><p>And while all of that is crucial for a successful fitness program,</p><p>What truly defines it and makes it stand out is the fact it focuses on <span style="color: red">long-term</span> growth & at the same time provides a unique experience that will help you <span style="color: red">BUILD</span> up that discipline to always stay on track without ever losing focus!</p><p>And that right there is the <span style="color: red">KEY</span> to unlocking <span style="color: red">genuine</span> and long-lasting progress.</p><p>The goal at the end of the day will always be to help you unlock your TRUE potential & get you towards your goals without any bullsh*tting</p><p>Now if you're looking for something that will truly <span style="color: red">LAST</span> & not waste your precious time, then stop waiting around and get to it.</p><p>And believe me...</p><p>This, is the real deal.</p>`
    }
    else {
        paragraph.innerHTML = `<p>Alright, so the issue with most fitness services nowadays is that they simply look way too bland and don't have that INSPIRING feel to it.</p><p>Seems like everyone is focusing way too much on selling you some mediocre ''gain muscle fast'' scheme that ends up benefiting you for a few months before ultimately going back to square one.</p><p>Now of course UEX offers you exclusive workouts you never tried before, customized meal plans, fast and modernized database and many other amazing features,</p><p>And while all of that is crucial for a successful fitness program,</p><p>What truly defines it and makes it stand out is the fact it focuses on long-term growth & at the same time provides a unique experience that will help you BUILD up that discipline to always stay on track without ever losing focus!</p><p>And that right there is the KEY to unlocking genuine and long-lasting progress.</p><p>The goal at the end of the day will always be to help you unlock your TRUE potential & get you towards your goals without any bullsh*tting</p><p>Now if you're looking for something that will truly LAST & not waste your precious time, then stop waiting around and get to it.</p><p>And believe me...</p><p>This, is the real deal.</p>`
    }
}

And here is me trying to include other sections as well, which pretty much ruins everything:

setInterval(()=> {
    changeColor()
}, 10)
function changeColor () {
    let paragraph1 = document.querySelector("#shopify-section-66f0799f-7a42-4714-84ff-d2b2d04e948c > div > div > div > div.rich-text__text.featured_text");
    let paragraph2 = document.querySelector("#shopify-section-484ac221-7750-481b-8ad9-9a3557414814 > div > div > div > div.rich-text__text.featured_text");
    if(!paragraph1 || !paragraph2) return;
    if(window.innerWidth < 756){
        paragraph1.innerHTML = `<p>Alright, so the issue with most fitness services nowadays is that they simply look way too bland and don't have that <span style="color:red">INSPIRING</span> feel to it.</p><p>Seems like everyone is focusing way too much on selling you some mediocre ''gain muscle fast'' scheme that ends up benefiting you for a few months before ultimately going back to square one.</p><p>Now of course UEX offers you exclusive workouts you never tried before, customized meal plans, fast and <span style="color: red">modernized</span> database and many other amazing features,</p><p>And while all of that is crucial for a successful fitness program,</p><p>What truly defines it and makes it stand out is the fact it focuses on <span style="color: red">long-term</span> growth & at the same time provides a unique experience that will help you <span style="color: red">BUILD</span> up that discipline to always stay on track without ever losing focus!</p><p>And that right there is the <span style="color: red">KEY</span> to unlocking <span style="color: red">genuine</span> and long-lasting progress.</p><p>The goal at the end of the day will always be to help you unlock your TRUE potential & get you towards your goals without any bullsh*tting</p><p>Now if you're looking for something that will truly <span style="color: red">LAST</span> & not waste your precious time, then stop waiting around and get to it.</p><p>And believe me...</p><p>This, is the real deal.</p>`
        paragraph2.innerHTML = `<p>So far over <span style="color:red">12.000+</span> people and counting have been able to achieve pure greatness & discover their true potential.</p>` 
    }
    else {
        paragraph1.innerHTML = `<p>Alright, so the issue with most fitness services nowadays is that they simply look way too bland and don't have that INSPIRING feel to it.</p><p>Seems like everyone is focusing way too much on selling you some mediocre ''gain muscle fast'' scheme that ends up benefiting you for a few months before ultimately going back to square one.</p><p>Now of course UEX offers you exclusive workouts you never tried before, customized meal plans, fast and modernized database and many other amazing features,</p><p>And while all of that is crucial for a successful fitness program,</p><p>What truly defines it and makes it stand out is the fact it focuses on long-term growth & at the same time provides a unique experience that will help you BUILD up that discipline to always stay on track without ever losing focus!</p><p>And that right there is the KEY to unlocking genuine and long-lasting progress.</p><p>The goal at the end of the day will always be to help you unlock your TRUE potential & get you towards your goals without any bullsh*tting</p><p>Now if you're looking for something that will truly LAST & not waste your precious time, then stop waiting around and get to it.</p><p>And believe me...</p><p>This, is the real deal.</p>`
        paragraph2.innerHTML = `<p>So far over 12.000+ people and counting have been able to achieve pure greatness & discover their true potential.</p>`
    }
}

How I should approach this situation so I can end up targeting multiple sections?

URL:jasaoslaj.com

Thanks in advance!

1 Like

Hi @jasa11

Can you point out which section paragraph you like to change the color? and also the other section? I would like to try by css code. Thanks!