Skip to main content
All CollectionsRule documentationCoding best practices
Use of spaces in attribute class selectors

Use of spaces in attribute class selectors

Starting Spring ’25, Salesforce no longer renders extra spaces between classes or empty class="" or style="" attributes

David Martin avatar
Written by David Martin
Updated over a week ago

What This Rule Does

This rule detects instances in JavaScript where a query selector targets an element using an exact string match for the class attribute that includes extra whitespace.

Starting Spring ’25, Salesforce no longer renders extra spaces between classes or empty class="" or style="" attributes, which means selectors that depend on whitespace or exact class string matches can break.


Why It Matters

Salesforce’s new rendering behavior removes extra whitespace in class attributes and eliminates empty class/style attributes entirely. This means that selectors like:

document.querySelector('[class=" highlight yellow "]');


will fail to find matching elements in the DOM. These queries rely on the presence of whitespace that no longer exists.

Instead, developers should use more flexible and reliable selectors like:

document.querySelector('.highlight.yellow');

How It Works

  • Scope: JavaScript source files within LWC modules

  • Match: Any querySelector or DOM method that looks for an exact [class="..."] selector with internal or trailing whitespace

  • Why: These selectors will no longer match the DOM due to changes in how Salesforce strips whitespace

Resources

Did this answer your question?