jquery node traversal
<script type= "Text/javascript" >//Node Traversal/*--next () method is used to get "node after" next to its first "homogeneous sibling" element--*/$ (function () {$ ("div"). Click (function () {alert (this). Next ("div"). Text ())//Effect: When you click AA, the bb pops up when you click The BB will pop up cc. An empty warning box pops up when you click CC (because the CC div node next to it is the P element.) So pop up an empty warning box), when clicking on the FF will pop up KK, when clicking on the KK will pop up an empty warning box (since KK This div node has no sibling div element next to it, so pop up an empty warning box)/*--nextall ( The--*/method is used to get the "node after" all of the sibling elements of the $ ("Div,p"). Click (function () {alert (this). Nextall (). text ()); When you click the div tag or the P tag, the text () of all the tabs after the current tab is clicked. }) $ ("Div,p"). Click (function () {alert (this). Nextall ("P"). text ());//when clicking D IV tag or P tag when pop-up click on the current tab after the full P tag of text (); }) $ ("div"). Click (function () {$ (this). Nextall ("div"). CSS ("Background", "re D "); When clicking on the div tag, set the background of all div tags behind it to red}) $ ("div"). Click (function () { $.each ($ (this). Nextall ("div"), function () {$ (this). CSS ("Background-color", "Red")})//When you click the div tag, all the div tags that follow it The background is set to red, which is the same as the one above (explanation: first get all the div tags behind the currently clicked Div tag. It is then traversed. The background of all DIV tags obtained is then set to red by the anonymous function below) Note that the two this meaning is not the same: The preceding this refers to the currently clicked Div tag. The following thi are: After getting to the "div tag" in the DIV tag that is currently clicked, traverse each of their div, followed by the thi: in the back of the anonymous function is processing the "currently traversed to the DIV tag" "Before the current click of the Div, The following anonymous function really handles the current Div "}" $ ("Div,p"). Click (function () {//$ (this). CSS ("Back Ground "," Red "); $ (this). Siblings (). CSS ("Background", "yellow"); Set the current clicked Div or P tag background to red, and the other sibling tag backgrounds to Yellow $ (this). CSS ("Background", "Red"). Siblings (). CSS ("Background", "yellow" ),//(equivalent to the above)}) </script>
jquery node traversal