Uncaught Error: Failed to save style!

I have a DomElement and I want to add a custom style called HighlightStyle on it.

// I have created custom style using:
const HighlightStyle = webflow.createStyle('highlight-element')
HighlightStyle.setProperties({ color: '#000000' })

// I am saving styles using:
const styles = await element.getStyles()
await element.setStyles([...styles, HighlightStyle])
await element.save()

But, it gives me an error: Uncaught (in promise) Error: Failed to save style!

Hey @Aditya_Borkar, welcome to the forum!

That error is occurring likely due to the class already being created on the project.

I’d check that class name is not already in use the project or try changing the name of the class.

You can also check the class name does not already exist using the getStyleByName function before trying to create the class: The Webflow Object