Home > Web Front-end > JS Tutorial > body text

Basic syntax of jquery

无忌哥哥
Release: 2018-06-29 10:51:37
Original
1878 people have browsed it

Basic syntax: $(selector).Method()

Basic process:

1-Use the selector to find the DOM element and package it to generate a jQuery object

2 -Call the jQuery method to operate on the found element

Summary: Find the element and then operate

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>4.jquery的基本语法</title>
</head>
<body>
<script type="text/javascript" src="../js/jquery-3.3.1.js"></script>
<script type="text/javascript">
// 选择到<span>标签中的文本,将它的前景色设置为红色
$(&#39;h2 span&#39;).css(&#39;color&#39;,&#39;red&#39;)
//我们还可以修改一个元素的内容
$(&#39;p+p&#39;).html(&#39;终于找到你了,开工吧&#39;)
//补充知识: $()还可以创建一个新元素
$(&#39;<img src="../images/zly.jpg" width="150">&#39;)
//为什么看不到呢?因为你还没有把这个元素添加到当前页面中
//insertAfter(元素):插入到指定元素的后面
// $(&#39;<img src="../images/zly.jpg" width="150">&#39;).insertAfter(&#39;h2&#39;)
//我们还可以对新插入的元素进一步的处理:例如修剪成圆形
$(&#39;<img src="../images/zly.jpg" width="150">&#39;).insertAfter(&#39;h2&#39;).css(&#39;border-radius&#39;,&#39;50%&#39;)
</script>
</body>
</html>
Copy after login

The above is the detailed content of Basic syntax of jquery. For more information, please follow other related articles on the PHP Chinese website!

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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!