Intro to jQuery: The Power Of jQ

作者: 此之木 | 来源:发表于2019-07-11 21:37 被阅读3次

How to select element?

In jQuery, we select an element with$().

$(“Selector Name”)

Selecting with “$” is very similar to querySelector and querySelectorAll. In that we provide a CSS style selector. Then, jQuery will return all matching element.

I updated the jQuery Demo HTML page a little by adding a <a> tag and id “test” in the list.

If I want to select the h1, I just need to type $(“h1”)[0] in the console, and it will return us the h1.

If I want to select the link, I just need to type $(“a”)[0], and it will return the link.

If I want to select the list with special id, I just need to type $(“#test”)[0], and it will return that list.

Moreover, selecting element with the dollar sign in jQuery will return a list even if there’s only one item. And it is much shorter and easier to write syntax.

How to manipulate style?

The .css() method is jQuery’s interface to styling.

$(select).css(property, value)

If I want to style the h1 to be pink, I just need to write $(“h1”).css(“color”, “pink”).

If I want to add a background and a border as well as change the color, I will pass in an object with styles.

In addition, we can style multiple elements at once.

If I want to change all list item color to be purple, I will do that:

The .css() method is very powerful because we can change individual properties and also pass on an object full of key pairs. With jQuery, if I have a collection of elements, it automatically loops over that and applies .css() to every single one.

相关文章

  • Intro to jQuery: The Power Of jQ

    How to select element? In jQuery, we select an element wi...

  • jQuery

    基本语法 效果 jQ html jQ Ajax jQuery概述 jQuery由美国人John Resig于200...

  • JQ

    简介 John Resig 2006年8月发布jQuery (22岁) JQ特点 jQuery代码风格 jQ...

  • jQuery 学习

    转载:菜鸟教程[https://www.runoob.com/jquery/jquery-intro.html] ...

  • 非常有用二

    1.jQuery 插件库[http://www.jq22.com/jq4-jq1] Look for less ,...

  • 24. 初始jQuery及公式

    jQuery API : https://jquery.cuishifeng.cn/官网 : https://jq...

  • npm 常用命令

    npm init npm install jquery npm i jquery npm uninstall jq...

  • JQuery&bootstrap

    内容回顾 jQuery的书写步骤引入JQ的包(xxx.js)书写JQ代码$(function(){ JQ代码...

  • Intro to jQuery: What Is jQuery

    What is jQuery? According to the web develop course,jQuer...

  • JQuery学习:第一篇

    相关知识点: jquery的介绍 jquery控制css jquery控制html jquery控制标签属性 jq...

网友评论

    本文标题:Intro to jQuery: The Power Of jQ

    本文链接:https://www.haomeiwen.com/subject/unhzaqtx.html