jquery style manipulation and property manipulation

Source: Internet
Author: User

One, style operation

Action inline style

// 获取div的样式$("div").css("width");$("div").css("color");//设置div的样式$("div").css("width","30px");$("div").css("height","30px");$("div").css({fontSize:"30px",color:"red"});

Special attention
The selector obtains more than one element, obtaining the information obtained by the first, for example: $ ("div"). CSS ("width"), gets the width of the first Div.

action Style class name

$("#div1").addClass("divClass2") //为id为div1的对象追加样式divClass2$("#div1").removeClass("divClass")  //移除id为div1的对象的class名为divClass的样式$("#div1").removeClass("divClass divClass2") //移除多个样式$("#div1").toggleClass("anotherClass") //重复切换anotherClass样式
二、属性操作

1. HTML () Remove or set HTML content

// 取出html内容var $htm = $(‘#div1‘).html();// 设置html内容$(‘#div1‘).html(‘<span>添加文字</span>‘);

2, prop () remove or set the value of a property

// 取出图片的地址var $src = $(‘#img1‘).prop(‘src‘);// 设置图片的地址和alt属性$(‘#img1‘).prop({src: "test.jpg", alt: "Test Image" });

jquery style manipulation and property manipulation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.