`

Changing element styling

CSS 
阅读更多

1.Adding and removing class names

 

Command syntax:addClass(names)

Adds the specified class name or class names to all elements in the wrapped set

Parameters

names (String) A string containing the class name to add or, if multiple class names are 

to be added, a space-delimited string of class names

Returns

The wrapped set

eg: $(a).addClass("classA classB" );// add classA and classB to all the links in the page

 

Command syntax:removeClass(names)

Removes the specified class name or class names from each element in the wrapped set

Parameters

names (String) A string containing the class name to remove or, if multiple class names 

are to be removed, a space-delimited string of class names

Returns

The wrapped set

 

Command syntax:toggleClass(name)

Adds the specified class name if it doesn’t exist on an element, or removes the name from 

elements that already possess the class name. Note that each element is tested individu-

ally, so some elements may have the class name added, and others may have it removed.

Parameters

name (String) A string containing the class name to toggle.

Returns

The wrapped set.

 

2.Getting and setting styles

 

Command syntax:css(name,value)

Sets the named CSS style property to the specified value for each matched element.

Parameters

name (String) The name of the CSS property to be set.

value (String|Number|Function) A string, number, or function containing the property value. If a function is passed as this parameter , it will be invoked for each element 

of the wrapped set with its return value serving as the value for the CSS property. The this property for each function invocation will be set to the element being evaluated.

Returns

The wrapped set.

eg: $("div.expandable").css("width",function() {

            return $(this).width() + 20 + "px";

     });//expand the width of all elements in the wrapped set by 20 pixels 

 

Command syntax:css(properties)

Sets the CSS properties specified as keys in the passed object to their associated values for all matched elements

Parameters

properties (Object) Specifies an object whose properties are copied as CSS properties to all elements in the wrapped set

Returns

The wrapped set

 

Command syntax:css(name)

Retrieves the computed value of the CSS property specified by name for the first element in the wrapped set

Parameters

name (String) Specifies the name of a CSS property whose computed value is to  be returned

Returns

The wrapped set

 

NOTE:Keep in mind that this variant of the css() command always returns a string, so if you need a number or some other type, you’ll need to parse the returned value.

 

Command syntax:width();height()

Retrieves the width or height of the first element of the wrapped set

Parameters

none

Returns

The computed width or height as a number

 

 

3.More useful style-related commands

 

 

Command syntax:hasClass(name)

Determines if any element of the matched set possesses the passed class name

Parameters

name (String) The class name to be checked

Returns

Returns true if any element in the wrapped set possesses the passed class name; false if not

 

eg: $("p:first").hasClass("surpriseMe");//identical to $("p:first").is(".surpriseMe")

 

分享到:
评论

相关推荐

    Android代码-termux-styling

    Termux:Styling A Termux add-on app to customize the terminal font and color theme. Termux:Styling on Google Play Termux:Styling on F-Droid When developing (or packaging), note that this app needs ...

    前端开源库-react-base16-styling

    **React-Base16 Styling库详解** 在前端开发领域,React已经成为构建用户界面的主流JavaScript库。然而,为了使应用具有美观且可定制的样式,开发者常常需要借助额外的库来实现。`react-base16-styling`就是这样一...

    Angular Styling Jumpstart

    根据提供的文件信息,以下是关于Angular组件样式设置(Angular Styling)的详细知识点总结: ### Angular组件样式的快速启动(Angular Styling Jumpstart) #### 知识点一:ngClass和ngStyle的使用 - **ngClass**...

    HTML5 Mastery: Semantics, Standards, and Styling

    - The `<svg>` element provides a way to create vector-based graphics that scale smoothly across different screen sizes and resolutions, making it ideal for icons and other graphical elements. ...

    Styling and Skinning.pdf

    根据提供的文件信息,“Styling and Skinning.pdf”主要讲解了Adobe Flex框架下的界面定制与换肤技术。下面将从以下几个方面进行深入解析: ### 一、Styling vs. Skinning #### Styling(样式定制) - **定义**:...

    英文原版-CSS Text Styling Your Words 1st Edition

    As a web designer, you probably spend more time working with text than any other element. With this concise guide, you’ll learn CSS3 properties for changing the appearance of text without altering ...

    styling, 使用JavaScript的全部功能创建CSS模块.zip

    styling, 使用JavaScript的全部功能创建CSS模块 样式style是使用JavaScript的全部强大功能编写组件样式的web pack 工具:import styling from 'styling'import {baseColor} from './theme'e

    qr-code-styling:在您的Web应用程序中自动生成样式化的QR码

    npm install qr-code-styling 用法 <!DOCTYPE html > < html lang =" en " > < head > < meta charset =" UTF-8 " > < title > QR Code Styling </ title > < script type =...

    styling-react:造型研究

    Create React App入门 该项目是通过引导的。 可用脚本 在项目目录中,可以运行: yarn start 在开发模式下运行应用程序。 打开在浏览器中查看它。 如果您进行编辑,则页面将重新加载。 您还将在控制台中看到任何...

    react-styling-loader:Webpack的React样式加载器模块

    Webpack的加载器模块用法var styles = require('react-styling!file.css'); 与其他样式的加载器一起使用。 var styles = require('react-styling!less!file.less'); 或者var styles = require('react-styling!sass!...

    Drupal 6 Themes: Create new themes for your Drupal 6 site with clean layout and powerful CSS styling

    Drupal is an award winning open source Content Management System (CMS).... * Create dynamic styling which responds to the content or the user * Discover tools that make theming easier and more efficient

    HTML5MasterySemanticsStandardsandStyling.pdf 英文原版

    HTML5 Mastery Semantics Standards and Styling

    dom-css-styling

    - **通过DOM操作设置样式**:通过元素的`style`属性直接设置内联样式,例如`element.style.color = 'red'`。 - **通过CSS类添加/移除样式**:使用`classList.add/removeClass/toggle`操作CSS类,实现样式切换。 -...

    Custom Print Story Cards Styling-crx插件

    《Custom Print Story Cards Styling-crx插件:个性化敏捷开发故事卡片样式》 在敏捷开发过程中,故事卡片(Story Cards)是一种重要的管理工具,用于记录和跟踪项目中的任务和需求。为了提高团队协作效率和视觉...

    termux-styling:Termux附加应用程序,用于自定义终端字体和颜色主题

    Termux:样式 附加应用程序可自定义终端字体和颜色主题。 在开发(或包装)时,请注意,此应用程序需要使用与Termux主应用程序相同的密钥签名,以便具有修改所需字体或颜色文件的权限。安装Termux:样式应用程序可以...

    styling-in-react:作为LeanJS培训的一部分提供的React练习中的样式

    在React中样式化本练习的目标是...入门您可以将其复制并粘贴到您的终端git clone https://github.com/leanjscom/styling-in-react.git && cd styling-in-react && yarn install && yarn start 或采取逐步路线git clone ...

    mendix-framework-styling

    mendix-framework-styling 这是 Mendix UX 团队创建的默认 SCSS 框架。 预览: 特征 使用 Bootstrap 框架 使用 SCSS 部分来帮助构建 CSS 使用 Compass 来利用 CSS3 mixins(不需要前缀) 如何使用自定义 CSS 想...

    3.1-cw-styling-forms

    标题 "3.1-cw-styling-forms" 暗示了这个主题是关于使用 CSS(层叠样式表)来美化和格式化 HTML 表单的。在网页设计中,表单是一个重要的交互元素,允许用户输入数据并与服务器进行交互。通过 CSS,我们可以对表单的...

Global site tag (gtag.js) - Google Analytics