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

How to modify css by id in jquery

醉折花枝作酒筹
Release: 2023-01-07 11:45:43
Original
2808 people have browsed it

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>
Copy after login

How to modify css by id in jquery

# Sets the specified CSS property for all matching elements.

$(selector).css(name,value)
Copy after login

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");
Copy after login

[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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template