Consider the following Code
If (node. nextsibling. classname = ...){
...
}
If node or node. nextsibling is null, an error is returned ). Therefore, the common solution code is
If (node) & (next = node. nextsibling )&&...){
...
}
Then, when multiple conditions are judged, the code will form the following situation:
If (
(Node )&&
(Node. nextsibling )&&
(Node. nextsibling. classname = ...)
...){
...
}
With the increasing judgment conditions, the code will become very ugly ".
There is a small "trick" to simplify the conditional judgment expression. We can add an empty object ({}) or zero (0) as an alternative.
If (next = (node | 0). nextsibling )){
...
}
Then, the above Code can be written in this way
If (node | 0). nextsibling | 0). classname = ...){
...
}
-- Split --
Personally, the above code is very streamlined from a certain perspective. However, in the actual coding process, especially when many people work together, these codes may cause some troubles to other developers.
As Pony said, If you are already using some frameworks, You need to analyze specific issues. For example, the above condition judgment code can be used using Yui encoding.
Yahoo. util. Dom. hasclass (El, classname)
It is more streamlined and easier to understand than the above Code.