# betterdocs/4.9.5/react-src/utils/selectMkb.js

BetterDocs – AI Documentation, Knowledge Base, MCP Server, Docs, Wikis, FAQ &amp; Chatbot, version 4.9.5. 24 lines.

- Page: https://pluginprobe.com/plugins/betterdocs/4.9.5/code/react-src/utils/selectMkb.js
- Raw: https://pluginprobe.com/plugins/betterdocs/4.9.5/raw/react-src/utils/selectMkb.js
- Modified: 2026-10-12T10:07:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/betterdocs/4.9.5/code/react-src/utils/selectMkb.js#L10-L20`.

```javascript
export default function ( $scope, $ ) {
    if( betterdocsCategoryGridConfig?.is_betterdocs_templates != 1 ) { //run this script only from outside betterdocs templates only, this script is made to determine set the kb and its value on cookie
        $('.betterdocs-category-grid-inner-wrapper .betterdocs-single-category-wrapper .betterdocs-category-link-btn').on('click', function(e){ //this is triggerd when clicked on explore more on category grid
            let secondTopLayer = $($($($(this)?.parent())?.parent())?.parent())?.parent();
            let topLayerMkbAttribute = $(secondTopLayer).attr('data-mkb-slug');
            if( topLayerMkbAttribute?.length > 0 ) {
                var expiryDate = new Date();
                var timeStamp = expiryDate.setDate(expiryDate.getDate() + 30).toString();
                document.cookie = `last_knowledge_base=${topLayerMkbAttribute}; expires=${timeStamp}; path=/;` ;
            }
        });

        $('.betterdocs-category-grid-inner-wrapper .betterdocs-single-category-wrapper .betterdocs-body .betterdocs-articles-list li a').on('click', function(e) { //this is triggerd when clicked on single doc list
            let secondTopLayer = $($($($($($(this).parent()).parent()).parent()).parent()).parent()).parent();
            let topLayerMkbAttribute = $(secondTopLayer).attr('data-mkb-slug');
            if( topLayerMkbAttribute?.length > 0 ) {
                var expiryDate = new Date();
                var timeStamp = expiryDate.setDate(expiryDate.getDate() + 30).toString();
                document.cookie = `last_knowledge_base=${topLayerMkbAttribute}; expires=${timeStamp}; path=/;` ;
            }
        });
    }
}

```
