Skip to content

Commit 0c52fbc

Browse files
committed
fix el null
1 parent e5f39ef commit 0c52fbc

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "docsify-sidebar-collapse",
3-
"version": "1.0.4",
3+
"version": "1.0.6",
44
"description": "sidebar-collapse plugin for docsify",
55
"main": "src",
66
"scripts": {

src/index.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,16 @@ $docsify.plugins = [
44
function(hook, vm) {
55
hook.doneEach(function(html, next) {
66
let el = document.querySelector('.sidebar-nav .active');
7-
el.classList.add('open');
8-
while (el && el.className !== 'sidebar-nav') {
9-
if (el.parentElement.tagName === 'LI') {
10-
el.parentElement.className = 'open';
7+
if (el) {
8+
el.classList.add('open');
9+
while (el.className !== 'sidebar-nav') {
10+
if (el.parentElement.tagName === 'LI') {
11+
el.parentElement.className = 'open';
12+
}
13+
el = el.parentElement;
1114
}
12-
el = el.parentElement;
1315
}
1416
next(html);
1517
});
16-
},
18+
}
1719
].concat($docsify.plugins || []);

0 commit comments

Comments
 (0)