Current location - Quotes Website - Personality signature - Javascript gets the id of the ul tag. How to change the background color and other attributes of Li in ul?
Javascript gets the id of the ul tag. How to change the background color and other attributes of Li in ul?
Use jquery's selector to get all the li elements in the ul, and then use the. The css(name, value) method provided by jquery is used to modify all the css properties of li, that is, background-color.

If the variable name of ul's id is ulid.

$ ("Li", "#"? +? ulid)。 css("background-color "," # CCC "); This uses jquery's selector rule $(selector 1, content).

Selector 1 is a selector. The content can be a selector, a jquery dom object, or a local dom object. In the code above, the content is a selector.

This means to select all the elements in the content that meet the selector 1. In the above code, it means "select all the li elements in ul whose id is the variable value of ulid".

The method. Css(name, value) is to change the css attribute named name to value, and if there is a numerical unit, the unit can be omitted. For example, the value of padding 30px can be written directly as. css("padding ",30)。

. Css(name) is to get the CSS attribute value with the name value. For example, Css("padding ") returns padding values without units, for example. Css("padding ") returns 30.