Home >Web Front-end >JS Tutorial >Jquery basic study notes_jquery
1. Attribute: Set a calculated attribute value for all matching elements
//Add attribute class="btn" for all inputs
//$("input").attr("class ","btn");
2. CSS: Add the specified class name to each matching element
//Add styles to all submit buttons
$("input :submit").addClass("btn");
3. Value: Get the current value of the first matching element
//Get the value of a button
/ /alert($("#Button1").val());
4. Html code: Get the html content of the first matching element. This function cannot be used with XML documents. But it can be used for XHTML documents.
//Output the html code between divs
//alert($("#div1").html());
//Reassign the html in the Div
//$("#div1").html("");
5. Text: Get the content of all matching elements.
The result is the text combined from the text content contained in all matching elements. This method works for both HTML and XML documents.
//Output the text value between divs
//alert($("#div1").text());
//For the text value in the div Text reassignment
//$("#div1").text("100");
6. //Select the radio button
$("#select1").val( "Option 2");
// if( $("#select1").val()=='Option 2')
// {
// alert("You selected option 2 ");
// }
7. Convert one or more DOM elements into jQuery objects
//Set the page background color
$(document.body).css(" background","#c0c0c0");
//Hide all elements in a form [not available]
//$(div.elements).hide();
8 , each usage uses each matching element as the context to execute a function
// $("button").click(function () {
// $("div").each(function (index , domEle) {
// // domEle == this
// $(domEle).css("backgroundColor", "yellow");
// if ($(this).is( "#stop")) {
// $("span").text("Stopped at div index #" index);
// return false;
// }
// });
// });
9. The return value of this function is consistent with the 'length' property of the jQuery object
//The number of buttons
//alert($ ("input:submit").size() " and " $("input:submit").length);
10. Get the set of all matching DOM elements
//alert($( "input").get().reverse());
//Get one of the matching elements. num indicates which matching element is obtained
//alert($("input").get(1));