Sample each method and common selectors in jquery
- 2020-03-30 03:29:43
- OfStack
<head>
<title></title>
<script src="jquery-1.4.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
//alert($("div").text());
//The array elements are processed one by one using anonymous functions.
$("div").each(function(key, value) {
//alert(key+value);
// alert($(value).text());
alert(this.innerHTML);
});
//This represents the dom element that is currently being traversed
$("div").each(function() {
alert($(this).text());
});
});
</script>
</head>
<body>
<div id="testDom">11111</div>
<div>2222</div>
<div>33333</div>
</body>
Common selectors:
1. Categories: $(" error ").
2. Id: $(" # daLong ").
3. Tag: $("div").
4. Property: $("div[name=apple]").
5. Form: $("input:checked").