Home  >  Article  >  Web Front-end  >  How to modify css by id in jquery

How to modify css by id in jquery

醉折花枝作酒筹
醉折花枝作酒筹Original
2021-07-26 14:43:382782browse

In jquery, you can use the "[att^=element]" selector to match elements starting with a certain id, and then use the css method to return or set one or more style attributes of the matched element, syntax format is "$(element).css(attribute, attribute value)".

How to modify css by id in jquery

The operating environment of this tutorial: Windows 7 system, jquery version 1.11.1, Dell G3 computer.

<ul id="foreignCurrencyTree_1_ul">
    <li id="foreignCurrencyTree_11_li">111111</li>
    <li id="foreignCurrencyTree_12_li">222222</li>
    <li id="foreignCurrencyTree_13_li">333333</li>
</ul>
<ul id="foreignCurrencyTree_2_ul">
    <li id="foreignCurrencyTree_21_li">111111</li>
    <li id="foreignCurrencyTree_22_li">222222</li>
    <li id="foreignCurrencyTree_23_li">333333</li>
</ul>

How to modify css by id in jquery

# Sets the specified CSS property for all matching elements.

$(selector).css(name,value)

How to modify css by id in jquery

//设置所有ul的overflow属性为hidden。
$(&#39;[id^=foreignCurrencyTree_][id$=_ul]&#39;).css("overflow","hidden");
//设置所有li的display属性为inline
$(&#39;[id^=foreignCurrencyTree_][id$=_li]&#39;).css("display","inline");

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of How to modify css by id in jquery. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn