给定一个包含段落元素的网页,任务是使用 jQuery 模块查找每个段落元素。我们必须从 HTML 页面中找到
元素,您可以通过使用元素选择器来完成此任务。元素选择器将根据元素的名称选择元素。
句法:
$("element name")
方法:
- 首先创建一个 HTML 页面并在
元素中写入一些内容。
- 在 jQuery 的帮助下,选择所有段落元素。
- 将一些 CSS 属性应用于
元素以查看更改。您可以使用 .css()方法来应用 CSS 属性。
示例 1:
HTML
GeeksForGeeks
This is a paragraph.
This is another paragraph.
HTML
GeeksForGeeks
Database
Database is a collection of inter-related
data which helps in efficient retrieval,
insertion and deletion of data from
database and organizes the data in the
form of tables, views
Operating System
An operating system acts as an intermediary
between the user of a computer and computer
hardware.
输出:
- 点击按钮前:
- 点击按钮后:
说明:从上面的例子中,您可以注意到,单击按钮后,每个段落元素的背景颜色都发生了变化。使用选择器,我们选择了所有段落元素,然后使用.css()方法为所有段落元素设置样式。
示例 2:
HTML
GeeksForGeeks
Database
Database is a collection of inter-related
data which helps in efficient retrieval,
insertion and deletion of data from
database and organizes the data in the
form of tables, views
Operating System
An operating system acts as an intermediary
between the user of a computer and computer
hardware.
输出:
- 点击按钮前:
- 点击按钮后: