{"id":5334,"date":"2021-11-25T04:25:47","date_gmt":"2021-11-25T04:25:47","guid":{"rendered":"https:\/\/studysection.com\/blog\/?p=5334"},"modified":"2021-11-25T05:06:03","modified_gmt":"2021-11-25T05:06:03","slug":"javascript-loading-div-is-displayed-only-when-the-debugger-is-on","status":"publish","type":"post","link":"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/","title":{"rendered":"Javascript | Loading div is displayed only when the debugger is on"},"content":{"rendered":"<p><strong>Problem:-<\/strong> I have added a loader div with id <strong><em>\u201cspin-loader\u201d<\/em><\/strong> on my web page to show processing of code. Its default style is <strong><em>display:none<\/em><\/strong>. Whenever I need to do any code processing, I start with <a href=\"https:\/\/studysection.com\/blog\/basics-of-jquery\/\">jquery<\/a> code as shown below:<br \/>\n<code>function someFun() {<br \/>\n     $('#spin-loader').show();<br \/>\n     \/\/ ajax code<br \/>\n     \/\/ some javascript or jquery processing<br \/>\n     $('#spin-loader').hide();<br \/>\n}<\/code><\/p>\n<p>I was facing a weird issue in this. Normally, it works perfectly. <strong><em>Loading icon div<\/em><\/strong> is displayed as it is the first line whenever <strong><em>someFun()<\/em><\/strong> function is called and it is hidden when ajax or normal javascript code processing is completed due to the last line inside function <strong><em>someFun()<\/em><\/strong>. The div having id <strong><em>\u201cspin-loader\u201d<\/em><\/strong> has my own CSS properties to show some code under processing.<\/p>\n<p>For a lot of pages, it worked. But for one page, it didn\u2019t work. <strong>Loading icon div<\/strong> is not displayed, but ajax and javascript code worked. Without Loading <strong><em>icon div<\/em><\/strong>, we never know code is in progress. The page should become a little faded and elements of the page should not be clickable until code is in progress. But, due to the CSS of the loader div being not changed to<strong> <em>\u201cdisplay:block\u201d<\/em><\/strong>, the user can click anywhere on the page.<br \/>\nLet\u2019s see how I resolved the issue.<\/p>\n<h2>Solution<\/h2>\n<p>First I added a line debugger; at the start to check whether the <strong><em>loader div<\/em><\/strong> becomes visible or not. My code becomes as follows:<br \/>\n<code>function someFun() {<br \/>\n     debugger;<br \/>\n     $('#spin-loader').show();<br \/>\n     \/\/ ajax code<br \/>\n     \/\/ some javascript or jquery processing<br \/>\n     $('#spin-loader').hide();<br \/>\n}<\/code><\/p>\n<p>While testing, the <strong>developer tool<\/strong> where the console tab is displayed should be open.<br \/>\nDuring testing, I observed that it processes the line <em style=\"color:red;\">$(&#8216;#spin-loader&#8217;).show();<\/em>  and loader div is displayed. But whenever I remove the line debugger; , the loading div does not become visible whenever the function <strong><em>someFun()<\/em><\/strong> is called.<\/p>\n<p><strong>Then I modify the code as follows and it worked:<\/strong><br \/>\n<code>function someFun() {<br \/>\n     $('#spin-loader').show();<br \/>\n     setTimeout(function() {<br \/>\n         \/\/ ajax code<br \/>\n         \/\/ some javascript or jquery processing<br \/>\n         $('#spin-loader').hide();<br \/>\n     }, 10);<br \/>\n}<\/code><\/p>\n<p>I put the whole code inside the <strong><em>setTimeout()<\/em><\/strong> function except the first line. Maybe the browser is busy with heavy code work and it didn\u2019t process the first line. When I gave a few 10ms which is very very small, then the first line was also executed and the rest of the code also worked perfectly.<\/p>\n<p><small><em>People having good knowledge of Financial accounting can get an <a href=\"https:\/\/www.studysection.com\/financial-accountant-advanced-diploma\">Accounting Certification Exams<\/a> from StudySection to increase their chances of getting a job in this field. You can get a foundation level certification if you are new to Financial accounting or you can go for advanced level certification if you have expert level skills in Financial accounting.<\/em><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem:- I have added a loader div with id \u201cspin-loader\u201d on my web page to show processing of code. Its<\/p>\n","protected":false},"author":1,"featured_media":5335,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[739,199],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Javascript | Loading div is displayed when the debugger is on - SS Blog<\/title>\n<meta name=\"description\" content=\"For a lot of pages, it worked. But for one page, it didn\u2019t work. Loading icon div is not displayed, but ajax and javascript code worked.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Javascript | Loading div is displayed when the debugger is on - SS Blog\" \/>\n<meta property=\"og:description\" content=\"For a lot of pages, it worked. But for one page, it didn\u2019t work. Loading icon div is not displayed, but ajax and javascript code worked.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog Posts on famous people, innovations and educational topics\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/studysection\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-25T04:25:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-25T05:06:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/11\/Javascript.png\" \/>\n\t<meta property=\"og:image:width\" content=\"300\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"admin-studysection-blog\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@studysection\" \/>\n<meta name=\"twitter:site\" content=\"@studysection\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin-studysection-blog\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/\"},\"author\":{\"name\":\"admin-studysection-blog\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\"},\"headline\":\"Javascript | Loading div is displayed only when the debugger is on\",\"datePublished\":\"2021-11-25T04:25:47+00:00\",\"dateModified\":\"2021-11-25T05:06:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/\"},\"wordCount\":408,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"keywords\":[\"debugger\",\"JavaScript\"],\"articleSection\":[\"Learn and Grow\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/\",\"url\":\"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/\",\"name\":\"Javascript | Loading div is displayed when the debugger is on - SS Blog\",\"isPartOf\":{\"@id\":\"https:\/\/studysection.com\/blog\/#website\"},\"datePublished\":\"2021-11-25T04:25:47+00:00\",\"dateModified\":\"2021-11-25T05:06:03+00:00\",\"description\":\"For a lot of pages, it worked. But for one page, it didn\u2019t work. Loading icon div is not displayed, but ajax and javascript code worked.\",\"breadcrumb\":{\"@id\":\"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/studysection.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Javascript | Loading div is displayed only when the debugger is on\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/studysection.com\/blog\/#website\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"name\":\"Blog Posts on famous people, innovations and educational topics\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/studysection.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/studysection.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/studysection.com\/blog\/#organization\",\"name\":\"StudySection\",\"url\":\"https:\/\/studysection.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"contentUrl\":\"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png\",\"width\":920,\"height\":440,\"caption\":\"StudySection\"},\"image\":{\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/studysection\",\"https:\/\/twitter.com\/studysection\",\"https:\/\/www.instagram.com\/study.section\/\",\"https:\/\/www.linkedin.com\/company\/studysection\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402\",\"name\":\"admin-studysection-blog\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g\",\"caption\":\"admin-studysection-blog\"},\"url\":\"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Javascript | Loading div is displayed when the debugger is on - SS Blog","description":"For a lot of pages, it worked. But for one page, it didn\u2019t work. Loading icon div is not displayed, but ajax and javascript code worked.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/","og_locale":"en_US","og_type":"article","og_title":"Javascript | Loading div is displayed when the debugger is on - SS Blog","og_description":"For a lot of pages, it worked. But for one page, it didn\u2019t work. Loading icon div is not displayed, but ajax and javascript code worked.","og_url":"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/","og_site_name":"Blog Posts on famous people, innovations and educational topics","article_publisher":"https:\/\/www.facebook.com\/studysection","article_published_time":"2021-11-25T04:25:47+00:00","article_modified_time":"2021-11-25T05:06:03+00:00","og_image":[{"width":300,"height":200,"url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/11\/Javascript.png","type":"image\/png"}],"author":"admin-studysection-blog","twitter_card":"summary_large_image","twitter_creator":"@studysection","twitter_site":"@studysection","twitter_misc":{"Written by":"admin-studysection-blog","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/#article","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/"},"author":{"name":"admin-studysection-blog","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402"},"headline":"Javascript | Loading div is displayed only when the debugger is on","datePublished":"2021-11-25T04:25:47+00:00","dateModified":"2021-11-25T05:06:03+00:00","mainEntityOfPage":{"@id":"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/"},"wordCount":408,"commentCount":0,"publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"keywords":["debugger","JavaScript"],"articleSection":["Learn and Grow"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/","url":"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/","name":"Javascript | Loading div is displayed when the debugger is on - SS Blog","isPartOf":{"@id":"https:\/\/studysection.com\/blog\/#website"},"datePublished":"2021-11-25T04:25:47+00:00","dateModified":"2021-11-25T05:06:03+00:00","description":"For a lot of pages, it worked. But for one page, it didn\u2019t work. Loading icon div is not displayed, but ajax and javascript code worked.","breadcrumb":{"@id":"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/studysection.com\/blog\/javascript-loading-div-is-displayed-only-when-the-debugger-is-on\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/studysection.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Javascript | Loading div is displayed only when the debugger is on"}]},{"@type":"WebSite","@id":"https:\/\/studysection.com\/blog\/#website","url":"https:\/\/studysection.com\/blog\/","name":"Blog Posts on famous people, innovations and educational topics","description":"","publisher":{"@id":"https:\/\/studysection.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/studysection.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/studysection.com\/blog\/#organization","name":"StudySection","url":"https:\/\/studysection.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","contentUrl":"https:\/\/studysection.com\/blog\/wp-content\/uploads\/2021\/10\/studySection-logo.png","width":920,"height":440,"caption":"StudySection"},"image":{"@id":"https:\/\/studysection.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/studysection","https:\/\/twitter.com\/studysection","https:\/\/www.instagram.com\/study.section\/","https:\/\/www.linkedin.com\/company\/studysection"]},{"@type":"Person","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/db367e2c29a12d1808fb1979edb3d402","name":"admin-studysection-blog","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/studysection.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/054ac87a6874df1932004239cd8eab36?s=96&d=mm&r=g","caption":"admin-studysection-blog"},"url":"https:\/\/studysection.com\/blog\/author\/admin-studysection-blog\/"}]}},"views":1317,"_links":{"self":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5334"}],"collection":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/comments?post=5334"}],"version-history":[{"count":4,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5334\/revisions"}],"predecessor-version":[{"id":5340,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/posts\/5334\/revisions\/5340"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media\/5335"}],"wp:attachment":[{"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/media?parent=5334"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/categories?post=5334"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/studysection.com\/blog\/wp-json\/wp\/v2\/tags?post=5334"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}