You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: page/using-jquery-core/selecting-elements.md
-37Lines changed: 0 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -57,43 +57,6 @@ However, this test doesn't work with `<tr>` elements. In the case of `<tr>` jQue
57
57
58
58
Elements that have not been added to the DOM will always be considered hidden, even if the CSS that would affect them would render them visible. See the [Manipulating Elements](/manipulating-elements) section to learn how to create and add elements to the DOM.
59
59
60
-
For reference, here is the code jQuery uses to determine whether an element is visible or hidden:
61
-
62
-
```
63
-
jQuery.expr.filters.hidden = function( elem ) {
64
-
65
-
var width = elem.offsetWidth;
66
-
var height = elem.offsetHeight;
67
-
var skip = elem.nodeName.toLowerCase() === "tr";
68
-
69
-
// does the element have 0 height, 0 width,
70
-
// and it's not a <tr>?
71
-
return width === 0 && height === 0 && !skip ?
72
-
73
-
// then it must be hidden
74
-
true :
75
-
76
-
// but if it has width and height
77
-
// and it's not a <tr>
78
-
width > 0 && height > 0 && !skip ?
79
-
80
-
// then it must be visible
81
-
false :
82
-
83
-
// if we get here, the element has width
84
-
// and height, but it's also a <tr>,
85
-
// so check its display property to
86
-
// decide whether it's hidden
87
-
jQuery.curCSS( elem, "display" ) === "none";
88
-
};
89
-
90
-
jQuery.expr.filters.visible = function( elem ) {
91
-
92
-
return !jQuery.expr.filters.hidden( elem );
93
-
94
-
};
95
-
```
96
-
97
60
## Choosing Selectors
98
61
99
62
Choosing good selectors is one way to improve JavaScript's performance. A little specificity — for example, including an element type when selecting elements by class name — can go a long way. On the other hand, too much specificity can be a bad thing. A selector such as `#myTable thead tr th.special` is overkill if a selector such as `#myTable th.special` will get the job done.
0 commit comments