(function ($) { // Ensure parent category is bold only if it has children $('.categorychecklist li').each(function () { var $this = $(this); if ($this.children('.children').length) { $this.children('label').css('font-weight', 'bold'); } }); // Collapsible subcategories $('.categorychecklist li').each(function () { if ($(this).children('.children').length) { $(this) .children('.children') .hide(); $(this) .children('label') .before( '[+] ' ); } }); $('.categorychecklist').on('click', 'a.toggle-subcategories', function (e) { e.preventDefault(); e.stopPropagation(); var $this = $(this); $this.parent() .children('.children') .slideToggle('fast', function () { $this.toggle(); $this.siblings('.toggle-subcategories').toggle(); }); }); // Auto-select parent categories when child is selected $('.categorychecklist').on('change', ':checkbox', function () { var $this = $(this); if ($this.is(':checked')) { // Check all parent categories $this.parents('li').children('input:checkbox').prop('checked', true); } else { // Uncheck child categories if parent is unchecked $this.closest('li').find('input:checkbox').prop('checked', false); } }); // Prevent default category from selecting unrelated categories $('.categorychecklist input[type="checkbox"]').on('change', function () { const defaultCategoryId = 1; // Replace with the ID of your default category (General Knowledge Mcqs) if ($(this).val() == defaultCategoryId) { if ($(this).is(':checked')) { // Uncheck all other categories $('.categorychecklist input[type="checkbox"]') .not(this) .prop('checked', false); // Clear 'Make Primary' for unrelated categories $('.categorychecklist li').each(function () { if ( $(this).find('input[type="checkbox"]').prop('checked') === false ) { $(this).find('.cat-item-action').remove(); } }); } } }); // Update 'Make Primary' visibility based on checked categories $('.categorychecklist input[type="checkbox"]').on('change', function () { const $parentLi = $(this).closest('li'); const isChecked = $(this).prop('checked'); if (isChecked) { $parentLi.find('.cat-item-action').show(); } else { $parentLi.find('.cat-item-action').remove(); } }); })(jQuery); {"id":9471,"date":"2017-11-17T21:39:04","date_gmt":"2017-11-17T16:39:04","guid":{"rendered":"https:\/\/pakmcqs.com\/?p=9471"},"modified":"2017-11-17T21:39:04","modified_gmt":"2017-11-17T16:39:04","slug":"usa-consist-of___________states","status":"publish","type":"post","link":"https:\/\/pakmcqs.com\/general_knowledge_mcqs\/usa-consist-of___________states","title":{"rendered":"USA consist of___________states?"},"content":{"rendered":"
A. 52 Submitted by: Dani khan<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":" A. 52 B. 50 C. 54 D. 51 Submitted by: Dani khan<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":{"0":"post-9471","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-general_knowledge_mcqs"},"plaintext":"A. 52\nB. 50<\/strong>\nC. 54\nD. 51\nSubmitted by: Dani khan<\/strong>\n","yoast_head":"\n
\nB. 50<\/strong>
\nC. 54
\nD. 51<\/p>\n