-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpager.js
More file actions
25 lines (25 loc) · 914 Bytes
/
pager.js
File metadata and controls
25 lines (25 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
function pagerActived(){
const pagers = document.querySelectorAll(`[data-tg="pager"]`);
pagers.forEach((pager =>{
const div = document.createElement(`div`);
div.setAttribute(`data-tg`, `numberDiv`)
const pages = pager.querySelectorAll(`[data-page]`);
pages[0].setAttribute(`data-pageon`,``)
for(let i=0; i<pages.length; i++){
const button = document.createElement(`button`);
button.setAttribute(`data-tg`,`pageNumber`)
button.textContent = `Page ${i+1}`;
div.appendChild(button);
}
pager.appendChild(div);
const buttons = pager.querySelectorAll(`[data-tg="pageNumber"]`);
buttons.forEach((button, i) =>{
button.addEventListener(`click`, function(){
const pages = pager.querySelectorAll(`[data-page]`);
pages.forEach((page =>{
page.removeAttribute(`data-pageon`)
}))
pages[i].setAttribute(`data-pageon`, ``);
}
)})}))}
export{pagerActived}