9951 explained code solutions for 126 technologies


jqueryHow do I use jQuery to set styles for an element?


jQuery can be used to set styles for an element using the .css() method. The syntax for the .css() method is as follows:

$(selector).css(property, value);

For example, to set the font size of all

elements to 20px, the following code can be used:

$("p").css("font-size", "20px");

Code explanation

  1. $(selector): An element selector that targets the element to which the styles will be applied.
  2. .css(): The jQuery method used to set styles for an element.
  3. property: The CSS property to be modified.
  4. value: The value of the CSS property.

Helpful links

Edit this code on GitHub