Home Web Front-end JS Tutorial Jquery basic study notes_jquery

Jquery basic study notes_jquery

May 16, 2016 pm 06:52 PM
jquery Base study notes

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));

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed explanation of jQuery reference methods: Quick start guide Detailed explanation of jQuery reference methods: Quick start guide Feb 27, 2024 pm 06:45 PM

Detailed explanation of jQuery reference methods: Quick start guide

How to use PUT request method in jQuery? How to use PUT request method in jQuery? Feb 28, 2024 pm 03:12 PM

How to use PUT request method in jQuery?

How to remove the height attribute of an element with jQuery? How to remove the height attribute of an element with jQuery? Feb 28, 2024 am 08:39 AM

How to remove the height attribute of an element with jQuery?

jQuery Tips: Quickly modify the text of all a tags on the page jQuery Tips: Quickly modify the text of all a tags on the page Feb 28, 2024 pm 09:06 PM

jQuery Tips: Quickly modify the text of all a tags on the page

Use jQuery to modify the text content of all a tags Use jQuery to modify the text content of all a tags Feb 28, 2024 pm 05:42 PM

Use jQuery to modify the text content of all a tags

Understand the role and application scenarios of eq in jQuery Understand the role and application scenarios of eq in jQuery Feb 28, 2024 pm 01:15 PM

Understand the role and application scenarios of eq in jQuery

How to tell if a jQuery element has a specific attribute? How to tell if a jQuery element has a specific attribute? Feb 29, 2024 am 09:03 AM

How to tell if a jQuery element has a specific attribute?

Summary of commonly used file operation functions in PHP Summary of commonly used file operation functions in PHP Apr 03, 2024 pm 02:52 PM

Summary of commonly used file operation functions in PHP

See all articles