JQuery操作HTML文檔

來源:互聯網
上載者:User

標籤:

一、JQuery選擇元素

1.$("p").click(function(){$(this).hide();}

點擊HTML頁面的任何p元素都會隱藏該p元素

2.$("#test").hide()

隱藏id=test的元素

3.$(".test").hide()

隱藏class=test的元素

總結為$(selector).action()

jQuery位於document.ready函數裡面

$(document).ready(function(){

jquery goes here

});

二、JQuery元素選取器

1..$("p.test")選取所有class=test的p元素

2.$("p#test")選取所有id=test的p元素

三、JQuery屬性選取器

$("[href]")選取所有帶有href屬性的元素

$("[href=‘#‘]")選取所有href屬性=#的元素

$("[href!=‘#‘]")選取所有帶有href值不等於#的元素

$("[href$=‘.jpg‘]")選取所有href值以“.jpg”結尾的元素

四、JQuery CSS選取器

可以改變HTML元素的CSS屬性

$("p").css("bachground-color","red");

$("ul li:first")每個<ul>中的第一個<li>

$("div#intro .test")選擇id=intro的div中class=test的div元素

五、JQuery獲得內容和屬性

text(),attr("data-date")

$("[data-date=‘2016-10-26‘]").attr("data-date")

六、JQuery css()方法

css()返回被選元素的一個或多個樣式屬性

$("p").css("background-color")返回收個匹配元素的background-color屬性值

設定css屬性

css("propertyname","value")

$("p").css("background-color","yellow")

設定多個css屬性

css({"propertyname1":"value1","propertyname2":"value2"})

 

JQuery操作HTML文檔

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.