Home > Article > Web Front-end > Basic syntax of jquery
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>标签中的文本,将它的前景色设置为红色 $('h2 span').css('color','red') //我们还可以修改一个元素的内容 $('p+p').html('终于找到你了,开工吧') //补充知识: $()还可以创建一个新元素 $('<img src="../images/zly.jpg" width="150">') //为什么看不到呢?因为你还没有把这个元素添加到当前页面中 //insertAfter(元素):插入到指定元素的后面 // $('<img src="../images/zly.jpg" width="150">').insertAfter('h2') //我们还可以对新插入的元素进一步的处理:例如修剪成圆形 $('<img src="../images/zly.jpg" width="150">').insertAfter('h2').css('border-radius','50%') </script> </body> </html>
The above is the detailed content of Basic syntax of jquery. For more information, please follow other related articles on the PHP Chinese website!