Attributes
1. Attributes
1.1 attr(name|PRoperties|key,value|key,fn)
1) Get attribute value $("img").attr("src");
2) Set attribute value $( "img").attr("title","Hello");$("img").attr({src:"img1.png",alt:"img1"})
3) Set attribute value $( "img").attr("alt",function(index,value){return value + index}) //index is the index of the current element, value is the original attribute value of "alt"
1.2 removeAttr(name)
Delete An attribute $("img").removeAttr("alt");
1.3 prop(name|properties|key,value|key,fn)
$("input[type='checkbox']").prop(" checked", true);
Used Delete the attribute set set by the .prop() method
1.5 The difference between attr() and prop()
Attributes with two attributes of true and false, such as checked, selected or disabled use prop(), others use attr()
2.CSS Class
2.1 addclass(class|fn)
$("p").addClasss("active focus");
$("ul li").addClass(function(i,class){return class+ i})
2.2 removeClass([name|fn])
$("p").removeClass("active");
$("p").removeClass(function(){return $(this).attr( "class")})
2.3 toggleClass(class|fn)
$("p").toggleClass("active");
$(".class").toggleClass(function(){
if($(this ).parent().is(".myClass"))
return "classtwo";
return "classtwo"; html([val|fn])
Get the content $("div").html() Get the html content of the first matching element
Set the content $("div").html("
"); $("p").text()