01/10/2018, 17:26
All Selector (“*”)
Dùng để lấy tất cả các elements bên trong một document như là head, script, title, h1, … Ví dụ minh họa: <html> <head> <title> gockinhghiem.com" </title> <script src="http://code.jquery.com/jquery-1.5.js"> </script> ...
Dùng để lấy tất cả các elements bên trong một document như là head, script, title, h1, …
Ví dụ minh họa:
<html>
<head>
<title> gockinhghiem.com" </title>
<script src="http://code.jquery.com/jquery-1.5.js"> </script>
</head>
<body>
<h1> Góc Kinh Nghiệm </h1>
<script>
var elementCount = $("*").length;
alert ("Tổng số elements là: " + elementCount);
</script>
</body>
</html>
Kết quả:
Trả về 7 elements gồm: html, head, title, 2 script, body, h1
Rất đơn giản! 