Vaadin 7 verticallayout dynamically change background color in java like js

vaadin 7 verticallayout dynamically change background color in java
the code no work
JavaScript.getCurrent().execute(“$(‘.backColorGrey’).css(‘background-color’, ‘purple’)”);

Are asking how to do the above in Vaadin 23 or 24? If yes, the answer is

verticalLayout.getElement().getStyle().set("background-color", "purple");

i need vaadin 7 code dynamically change color verticallayout

							JavaScript.getCurrent().execute("$('.backColorGrey').css('background-color', 'red')"); no work vaadin7

This probably does not work because it is not plain JavaScript, but something that uses Jquery, and you would need to import Jquery as well in your application using @JavaScript annotation in order to get it work.

But you might be trying to do this in totally wrong way. If you are actually not needing to set arbitrary colors, but change back and forth a predefined color, you have much simpler way to do that.

Use in Java


And then add in your theme .scss file the style rule

.red { 
   background-color: red;

this is not work dynamic always show red color i change dynamic color change

The $(...) function is from jQuery, which doesn’t exist by default.

Vaadin 7 and 8 do not have Element API built-in, but it is available as an add-on

It gives you additional API to for example modify styles dynamically

See the demo code