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