{"id":5499,"date":"2020-04-06T13:48:55","date_gmt":"2020-04-06T08:18:55","guid":{"rendered":"https:\/\/pheonixsolutions.com\/blog\/?p=5499"},"modified":"2020-04-06T19:04:03","modified_gmt":"2020-04-06T13:34:03","slug":"jquery-traversing","status":"publish","type":"post","link":"https:\/\/pheonixsolutions.com\/blog\/jquery-traversing\/","title":{"rendered":"JQUERY &#8211; TRAVERSING"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">JQUERY &#8211; TRAVERSING<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">06\/04\/2020<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">JQUERY &#8211; Traversing is used to select HTML element based on the relationship. It supports lots of methods to find the element.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Jquery &#8211; siblings()<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This method select all the siblings of the selected element. <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;style&gt;\n.siblings  { \n  display: block;\n   padding: 5px; \n  color: gray;\n  text-align: center;\n  margin: 15px;\n}\n&lt;\/style&gt;\n<a href=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js\" target=\"_blank\" rel=\"noopener\">https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js<\/a>\n&lt;script&gt;\n$(document).ready(function(){\n  $(\"p\").siblings().css({\"color\": \"blue\"});\n});\n&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body class=\"siblings\"&gt;\n\n&lt;div&gt;Parent \n  &lt;p&gt;child 1&lt;\/p&gt;\n  &lt;span&gt;child 2&lt;\/span&gt;\n  &lt;p&gt;child 3&lt;\/p&gt;\n  &lt;h3&gt;child 4&lt;\/h3&gt;\n  \n&lt;\/div&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n\n\n\n<figure class=\"wp-block-gallery columns-1 is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\"><ul class=\"blocks-gallery-grid\"><li class=\"blocks-gallery-item\"><figure><img fetchpriority=\"high\" decoding=\"async\" width=\"530\" height=\"231\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-12.51.11.png\" alt=\"\" data-id=\"5500\" data-full-url=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-12.51.11.png\" data-link=\"https:\/\/pheonixsolutions.com\/blog\/?attachment_id=5500\" class=\"wp-image-5500\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-12.51.11.png 530w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-12.51.11-300x131.png 300w\" sizes=\"(max-width: 530px) 100vw, 530px\" \/><\/figure><\/li><\/ul><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Jquery &#8211; next()<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This method selects the next sibling of the given element.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In the following method, it will select the next element of the &lt;p&gt; tag.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;style&gt;\n.siblings  { \n  display: block;\n   padding: 5px; \n  color: gray;\n  text-align: center;\n  margin: 15px;\n}\n&lt;\/style&gt;\n<a href=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js\" target=\"_blank\" rel=\"noopener\">https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js<\/a>\n&lt;script&gt;\n$(document).ready(function(){\n  $(\"p\").next().css({\"color\": \"blue\"});\n});\n&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body class=\"siblings\"&gt;\n\n&lt;div&gt;Parent \n  &lt;p&gt;child 1&lt;\/p&gt;\n  &lt;span&gt;child 2&lt;\/span&gt;\n  &lt;p&gt;child 3&lt;\/p&gt;\n  &lt;h3&gt;child 4&lt;\/h3&gt;\n  \n&lt;\/div&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"425\" height=\"179\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.02.41.png\" alt=\"\" class=\"wp-image-5502\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.02.41.png 425w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.02.41-300x126.png 300w\" sizes=\"(max-width: 425px) 100vw, 425px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Jquery &#8211; nextAll()<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">nextAll() method select all the next sibling of the given elemnt.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following method will select all the next sibling of the &lt;h1&gt;.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;style&gt;\n.siblings  { \n  display: block;\n   padding: 5px; \n  color: gray;\n  text-align: center;\n  margin: 15px;\n}\n&lt;\/style&gt;\n<a href=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js\" target=\"_blank\" rel=\"noopener\">https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js<\/a>\n&lt;script&gt;\n$(document).ready(function(){\n  $(\"h1\").nextAll().css({\"color\": \"blue\"});\n});\n&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body class=\"siblings\"&gt;\n\n&lt;div&gt;Parent \n  \n  &lt;span&gt;child 1&lt;\/span&gt;\n  &lt;h1&gt;child 2&lt;\/h1&gt;\n  &lt;p&gt;child 3&lt;\/p&gt;\n  \n  &lt;h3&gt;child 4&lt;\/h3&gt;\n  \n&lt;\/div&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"333\" height=\"189\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.08.26.png\" alt=\"\" class=\"wp-image-5504\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.08.26.png 333w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.08.26-300x170.png 300w\" sizes=\"(max-width: 333px) 100vw, 333px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Jquery &#8211; nextUntil()<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This method select all the elements between the given two-element.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;style&gt;\n.siblings  { \n  display: block;\n   padding: 5px; \n  color: gray;\n  text-align: center;\n  margin: 15px;\n}\n&lt;\/style&gt;\n<a href=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js\" target=\"_blank\" rel=\"noopener\">https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js<\/a>\n&lt;script&gt;\n$(document).ready(function(){\n  $(\"h1\").nextUntil(\"h4\").css({\"color\": \"blue\"});\n});\n&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body class=\"siblings\"&gt;\n\n&lt;div&gt;Parent \n  &lt;h1&gt;siblings&lt;\/h1&gt;\n  &lt;p&gt;child 1&lt;\/p&gt;\n  &lt;h2&gt;child 2&lt;\/h2&gt;\n  &lt;p&gt;child 3&lt;\/p&gt;\n  \n  &lt;h3&gt;child 4&lt;\/h3&gt;\n  &lt;h4&gt;child 5&lt;\/h4&gt;\n  &lt;h5&gt;child 6&lt;\/h5&gt;\n  \n&lt;\/div&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"461\" height=\"366\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.25.17.png\" alt=\"\" class=\"wp-image-5506\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.25.17.png 461w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.25.17-300x238.png 300w\" sizes=\"(max-width: 461px) 100vw, 461px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Jquery &#8211; prev()<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This method selects the previous element of the given element.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The following method selects the previous siblings of the &lt;p&gt; tag.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;style&gt;\n.siblings  { \n  display: block;\n   padding: 5px; \n  color: gray;\n  text-align: center;\n  margin: 15px;\n}\n&lt;\/style&gt;\n<a href=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js\" target=\"_blank\" rel=\"noopener\">https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js<\/a>\n&lt;script&gt;\n$(document).ready(function(){\n  $(\"p\").prev().css({\"color\": \"blue\"});\n});\n&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body class=\"siblings\"&gt;\n\n&lt;div&gt;Parent \n  &lt;h1&gt;siblings&lt;\/h1&gt;\n  &lt;p&gt;child 1&lt;\/p&gt;\n  &lt;h2&gt;child 2&lt;\/h2&gt;\n  &lt;p&gt;child 3&lt;\/p&gt;\n  \n  &lt;h3&gt;child 4&lt;\/h3&gt;\n  &lt;h4&gt;child 5&lt;\/h4&gt;\n  &lt;h5&gt;child 6&lt;\/h5&gt;\n  \n&lt;\/div&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"457\" height=\"378\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.33.12.png\" alt=\"\" class=\"wp-image-5507\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.33.12.png 457w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.33.12-300x248.png 300w\" sizes=\"(max-width: 457px) 100vw, 457px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Jquery &#8211; <\/strong>prevAll<strong>()<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This method selects all the previous elements of the given element.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;head&gt;\n&lt;style&gt;\n.siblings  { \n  display: block;\n   padding: 5px; \n  color: gray;\n  text-align: center;\n  margin: 15px;\n}\n&lt;\/style&gt;\n<a href=\"https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js\" target=\"_blank\" rel=\"noopener\">https:\/\/ajax.googleapis.com\/ajax\/libs\/jquery\/3.4.1\/jquery.min.js<\/a>\n&lt;script&gt;\n$(document).ready(function(){\n  $(\"h4\").prevAll().css({\"color\": \"blue\"});\n});\n&lt;\/script&gt;\n&lt;\/head&gt;\n&lt;body class=\"siblings\"&gt;\n\n&lt;div&gt;Parent \n  &lt;h1&gt;siblings&lt;\/h1&gt;\n  &lt;p&gt;child 1&lt;\/p&gt;\n  &lt;h2&gt;child 2&lt;\/h2&gt;\n  &lt;p&gt;child 3&lt;\/p&gt;\n  \n  &lt;h3&gt;child 4&lt;\/h3&gt;\n  &lt;h4&gt;child 5&lt;\/h4&gt;\n  &lt;h5&gt;child 6&lt;\/h5&gt;\n  \n&lt;\/div&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;\n<\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"442\" height=\"363\" src=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.41.09.png\" alt=\"\" class=\"wp-image-5509\" srcset=\"https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.41.09.png 442w, https:\/\/pheonixsolutions.com\/blog\/wp-content\/uploads\/2020\/04\/Screenshot-2020-04-06-at-13.41.09-300x246.png 300w\" sizes=\"(max-width: 442px) 100vw, 442px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Thanks for using&nbsp;<a href=\"https:\/\/pheonixsolutions.com\/\">pheonixsolutions<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>JQUERY &#8211; TRAVERSING 06\/04\/2020 JQUERY &#8211; Traversing is used to select HTML element based on the relationship. It supports lots [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1022],"tags":[751,760,761,759],"class_list":["post-5499","post","type-post","status-publish","format-standard","hentry","category-web-architecture","tag-jquery","tag-next","tag-nextall","tag-siblings","psol-cat-web-architecture"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/phn2x7-1qH","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5499","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=5499"}],"version-history":[{"count":0,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/5499\/revisions"}],"wp:attachment":[{"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=5499"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=5499"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pheonixsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=5499"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}