Skip to content

Commit

Permalink
menu title from textContent
Browse files Browse the repository at this point in the history
  • Loading branch information
elproffesore committed Dec 7, 2023
1 parent 3111b21 commit f5153ce
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions js/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ async function updateView(){
session.items.map((item,itemIndex) => {
updateItemPosition(item,itemIndex)
})
//create menu item with scroll function
let menuItem = document.createElement('p')
let html = domParser.parseFromString(marked.parse(session.text), 'text/html');
let title = html.getElementsByTagName('h1')
if(title.length == 0){
title = html.getElementsByTagName('h2')[0]
title = html.getElementsByTagName('h2')[0].textContent
}else{
title = title[0]
title = title[0].textContent
}
menuItem.innerHTML = title.innerHTML
menuItem.innerHTML = title
menuItem.addEventListener("click", () => {
window.scrollTo({top: session.index == 0 ? 0 :session.margin + (session.height/2),behavior: 'smooth' })
})
Expand Down

0 comments on commit f5153ce

Please sign in to comment.