CSS: .css() returns undefined for custom properties on detached elements
Description
Calling .css() to read a CSS custom property from a detached element returns undefined, even when jQuery just set that inline property.
For a detached element in Chrome, getComputedStyle( elem ).getPropertyValue( "--foo" ) returns an empty string and computed[ "--foo" ] is undefined. That leaves ret as undefined, so the current ret === "" detached fallback is skipped. The fallback delegates to jQuery.style(), whose getter also reads style[ name ]; custom properties require getPropertyValue().
Minimal reproduction against current main (7e1efd77):
const elem = jQuery( "<div>" ).css( "--foo", "5" );
console.log( elem[ 0 ].style.getPropertyValue( "--foo" ) ); // "5"
console.log( elem.css( "--foo" ) ); // undefined
Expected: elem.css( "--foo" ) returns "5", matching attached elements and the value stored in the inline style.
Actual: it returns undefined.
Tested in Chrome 150 on macOS. The existing custom-property tests only exercise attached elements.
Link to test case
The reduced code above reproduces after loading the latest development build. It was also verified against a local build of main at 7e1efd77.
Screenshot
After the focused fix, the same detached element returns the inline custom-property value:
Closing per our contribution policy.
This submission doesn't correspond to a problem encountered in real usage and appears to have been produced by pointing an automated tool at the repository. Per the policy, we close these without review regardless of technical merit. Repeat submissions may result in a ban.
If you hit a genuine problem while using jQuery, please open an issue with a test case describing how you encountered it before submitting code.
I hadn't clocked that @timmywil - apologies!
Was looking for a way to contribute in my week off, appreciate all of my PRs will be edge cases.
I've noted, and taken on board, your comments :)