---
title: "JQUERY对页面属性的选择控制（整理）"
author: "lym6520"
date: "2009-03-24T13:49:37Z"
tags: ["CSS", "HTML", "jQuery"]
slug: "jquery"
draft: false
lastmod: "2009-03-24T13:49:37Z"
id: 354183
url: "https://lym6520.iteye.com/blog/354183"
---

JQUERY对页面属性的选择控制（整理）

**1.#id：通过元素id**

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

                    "[http://www.w3.org/TR/html4/loose.dtd](http://www.w3.org/TR/html4/loose.dtd "http://www.w3.org/TR/html4/loose.dtd")"&gt;

&lt;html&gt;

&lt;head&gt;

  &lt;script src="[http://code.jquery.com/jquery-latest.js](http://code.jquery.com/jquery-latest.js "http://code.jquery.com/jquery-latest.js")"&gt;&lt;/script&gt;

 

  &lt;script&gt;

  $(document).ready(function(){

    [$](http://docs.jquery.com/Core/%24 "Core/$")("#myDiv").[css](http://docs.jquery.com/CSS/css "CSS/css")("border","3px solid red");

  });

  &lt;/script&gt;

  &lt;style&gt;

  div {

    width: 90px;

    height: 90px;

    float:left;

    padding: 5px;

    margin: 5px;

    background-color: #EEEEEE;

  }

  &lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;

  &lt;div id="notMe"&gt;&lt;p&gt;id="notMe"&lt;/p&gt;&lt;/div&gt;

  &lt;div id="myDiv"&gt;id="myDiv"&lt;/div&gt;

&lt;/body&gt;

&lt;/html&gt;

**2.element：通过页面元素名称，如div，span，p等**

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

                    "[http://www.w3.org/TR/html4/loose.dtd](http://www.w3.org/TR/html4/loose.dtd "http://www.w3.org/TR/html4/loose.dtd")"&gt;

&lt;html&gt;

&lt;head&gt;

  &lt;script src="[http://code.jquery.com/jquery-latest.js](http://code.jquery.com/jquery-latest.js "http://code.jquery.com/jquery-latest.js")"&gt;&lt;/script&gt;

 

  &lt;script&gt;

  $(document).ready(function(){

    $("div").[css](http://docs.jquery.com/CSS/css "CSS/css")("border","3px solid red");

  });

  &lt;/script&gt;

  &lt;style&gt;

  div,span {

    width: 60px;

    height: 60px;

    float:left;

    padding: 10px;

    margin: 10px;

    background-color: #EEEEEE;

  }

  &lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;

  &lt;div&gt;DIV1&lt;/div&gt;

  &lt;div&gt;DIV2&lt;/div&gt;

  &lt;span&gt;SPAN&lt;/span&gt;

&lt;/body&gt;

&lt;/html&gt;

3.**.class****：通过class名称，注意“.”号**

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

                    "[http://www.w3.org/TR/html4/loose.dtd](http://www.w3.org/TR/html4/loose.dtd "http://www.w3.org/TR/html4/loose.dtd")"&gt;

&lt;html&gt;

&lt;head&gt;

  &lt;script src="[http://code.jquery.com/jquery-latest.js](http://code.jquery.com/jquery-latest.js "http://code.jquery.com/jquery-latest.js")"&gt;&lt;/script&gt;

 

  &lt;script&gt;

  $(document).ready(function(){

    $(".myClass").[css](http://docs.jquery.com/CSS/css "CSS/css")("border","3px solid red");

  });

  &lt;/script&gt;

  &lt;style&gt;

  div,span {

    width: 150px;

    height: 60px;

    float:left;

    padding: 10px;

    margin: 10px;

    background-color: #EEEEEE;

  }

  &lt;/style&gt;

&lt;/head&gt;

&lt;body&gt;

  &lt;div class="notMe"&gt;div class="notMe"&lt;/div&gt;

  &lt;div class="myClass"&gt;div class="myClass"&lt;/div&gt;

  &lt;span class="myClass"&gt;span class="myClass"&lt;/span&gt;

&lt;/body&gt;

&lt;/html&gt;

4.**\*:****通过“\*”号匹配所有**

&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

                    "[http://www.w3.org/TR/html4/loose.dtd](http://www.w3.org/TR/html4/loose.dtd "http://www.w3.org/TR/html4/loose.dtd")"&gt;

&lt;html&gt;

&lt;head&gt;

  &lt;script src="[http://code.jquery.com/jquery-latest.js](http://code.jquery.com/jquery-latest.js "http://code.jquery.com/jquery-latest.js")"&gt;&lt;/script&gt;

 

  &lt;script&gt;

  $(document).ready(function(){

    $("\*").[css](http://docs.jquery.com/CSS/css "CSS/css")("border","3px solid red");

  });

  &lt;/script&gt;

  &lt;style&gt;

  div,span,p {

    width: 150px;

    height: 60px;

    float:left;

    padding: 10px;

    margin: 10px;

    background-color: #EEEEEE;

  }