Examples of the each method and common selector in jquery, jqueryeach
<Head> <title> </title> <script src = "jquery-1.4.2.js" type = "text/javascript"> </script> <script type = "text/javascript"> $ (function () {// alert ($ ("div "). text (); // use anonymous functions to process array elements one by one. $ ("Div "). each (function (key, value) {// alert (key + value); // alert ($ (value ). text (); alert (this. innerHTML) ;}); // this indicates the dom element currently traversed $ ("div "). each (function () {alert ($ (this ). text ());});}); </script>
Common selector:
1. Class: $ (". error ").
2. id: $ ("# daLong ").
3. Tag: $ ("div ").
4. attributes: $ ("div [name = apple]").
5. Form: $ ("input: checked ").
Question about each in jQuery?
. Each (function (). This is a loop. You can add parameters to a function.
How to Use the jquery each method?
Each is used for traversing, for example, traversing a hashmap
$. Each (json. map, function (k, v ){
Document. getElementById (k). value = v;
})