Adding content between previous and next buttons with the use of JavaScript

After successfully implementing the functionality for the previous and next buttons in my script, I was requested to include the date between the buttons like this:

btnPrev issueDate btnNext
< Date >

Although I tried adding the date between the PREV and NEXT buttons in the code, it doesn't show up on the page. How can I properly insert text between those two buttons?

type: "span",
textContent: "November 1, 2022",
...this.btnIssue,
});

This is the complete script:

constructor(selector, options = {}) {
Object.assign(
this, {
EL: document.querySelector(selector),
page: 0,
selector,
// btnTabs: {}, // Custom attributes for tabs (navigation) buttons
btnPrev: {}, // Custom attributes for PREV button
btnNext: {}, // Custom attributes for NEXT button
classActive: "is-active",
onChange: () => {},
},
options
);
this.EL_pages = this.EL.children;
this.EL_pagination = document.querySelectorAll(`[data-tabs-pagination="${this.selector}"]`);
this.EL_navigation = document.querySelectorAll(`[data-tabs-navigation="${this.selector}"]`);
this.total = this.EL_pages.length;
this.EL_prev = this._ELNew("button", {
type: "button",
textContent: "<",
onclick: () => this.prev(),
...this.btnPrev,
});
this.EL_issue = this._ELNew("span", {
type: "span",
textContent: "November 1, 2022",
});
this.EL_next = this._ELNew("button", {
type: "button",
textContent: ">",
onclick: () => this.next(),
...this.btnNext,
});
this.EL_buttons = Array.from(Array(this.total)).reduce((arr, _, i) => {
const EL_btn = this._ELNew("button", {
type: "button",
textContent: i + 1,
onclick: () => (this._page = i),
...this.btnPagination,
});
arr.push(EL_btn);
return arr;
}, []);
this._init();
}

// Utility function - New element
_ELNew = (sel, attr) => Object.assign(document.createElement(sel), attr || {});

// Fix negative modulo index 
_mod = (n) => ((n % this.total) + this.total) % this.total;

// Initialize
_init() {
// Append nav buttons to DOM
this.EL_pagination.forEach((EL) => EL.append(...this.EL_buttons));
this.EL_navigation.forEach((EL) => EL.append(this.EL_prev, this.EL_next));

// Set current page
this._page = this.page;
}

prev(n = 1) {
this._page -= n;
return this;
}

next(n = 1) {
this._page += n;
return this;
}

show(idx) {
this._page = idx;
return this;
}

set _page(n) {
this.page = this._mod(n);
[...this.EL_pages, ...this.EL_buttons].forEach((EL) => EL.classList.remove(this.classActive));
[this.EL_pages[this.page], this.EL_buttons[this.page]].forEach((EL) => EL.classList.add(this.classActive));
// Provide a callback
this.onChange.call(this);
}

get _page() {
return this.page;
}
}


// Use like:
const mySectionTabs = new Tabs("#issue-nav", {
onChange() {
console.clear();
console.log(`Current page index: ${this.page}`);
}
});

Answer №1

I accidentally omitted the reference to "this.EL_issue" and have rectified that mistake now.

this.EL_navigation.forEach((EL) => EL.append(this.EL_prev, this.EL_issue, this.EL_next));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Experiencing difficulty with utilizing ajax for transmitting form data to a php script

I am facing an issue with sending form values to another PHP file. After confirming the data submission, I do not receive any alert notification from the PHP file. Here's what I have tried so far: I created a test file with a simplified version of th ...

The issue of gallery image loading with the galleryView jQuery plugin is causing problems

Hi fellow developers, I could really use some assistance. I've been working on implementing the jquery galleryview plugin for my image gallery (check out my gallery here). Unfortunately, I'm running into an issue where the gallery is not loading ...

Assessing the value of a variable or expression embedded within a string in Sass

Creating a mixin to set a div to transparent requires special attention to evaluate a variable in a string. The -ms-filter line must be quoted and should include the result of a calculation ($amount * 100). How can I successfully incorporate this into my ...

Error: Attempting to access property of undefined variable

I have searched for similar titles related to my issue, but I still haven't found a solution. The error I am encountering when clicking on agent_dashboard on the side panel is as follows: txtDisplayName = <div style="border:1px solid #990000;paddi ...

What are some ways I can showcase the outcomes of my multiple choice quiz?

I need help with my multiple choice quiz. I want to display the answers under each question and highlight the correct one in bold. Here is the current code: function check() { var question1 = document.quiz.question1.value; var question2 = document.q ...

Looking to migrate my current firebase/react project to typescript. Any tips on how to batch.update?

Having difficulty resolving a typescript error related to batch.update in my code. const batch = db.batch(); const listingDoc = await db.collection("listings").doc(listingID).get(); const listingData = listingDoc.data( ...

Solving the issue of IE7 div overflow-y: scroll causing content to be obscured by the scrollbar

I am facing an issue with a table inside a div (#body) that scrolls along the y-axis. Specifically, in Internet Explorer, the scrollbar is hiding part of the last table cell behind it, causing a shift in the layout of the table columns. This problem does n ...

Tips for retrieving the ajax results for multiple deferred calls using jQuery

I am struggling to utilize the jQuery deferred function as illustrated in the following code snippet. <script type="text/javascript"> var appUrls = { GetDataUrl : '@Url.Action("GetData")' }; ...

Getting AJAX data in PHP: A comprehensive guide

As a student, I am working on creating a simple form for my website that will utilize ajax to save the submitted details to the database using PHP. I prefer not to use any external libraries like jQuery. Although I have successfully implemented the ajax "g ...

Creating a JavaScript function to download specific sections of an HTML page

Currently, I am implementing PHP MySQL in my HTML page. I have already utilized several div elements in my page. I successfully created a print button that prints a specific div on the page. Now, I am looking to add a download button that will allow users ...

Troubleshooting a malfunctioning PHP form that uses jQuery and AJAX

Snippet of HTML code: <form class="contact_form" action="" name="contact_form"> <ul><li> <input type="email" name="email" placeholder="Please enter your email here" required /> </li><li> <button class="submit" type=" ...

"putting into a state of freezing" an entry field

My <input type="text" /> element needs to stop accepting text at a certain point. However, I'm unable to change the type to type="button" for some reason. What is the best way to make my <input> element stop accepting text? ...

bottom of the page contains the solution

I am currently working on creating a print stylesheet for my website. On each page, there is a footer that needs to be positioned at the bottom of the printed page, but only if there is a spacing of 30pt between the main content and the footer. In cases wh ...

JavaScript method not properly sorting the last nested array

I am having trouble with sorting the last nested array using arr[i].sort(). Despite trying various methods such as FOR and WHILE loops along with different operators, I still cannot achieve the desired result. Can someone help me identify what I am doing w ...

Altering an element's visibility from 'none' will trigger its animation to play once again

Take a look at the snippet below and you'll see that the sliding animation plays twice - once when the .addClass statement runs, and again when #test's display is switched to 'initial' (timeouts are in place to help visualize the issue) ...

How to use JQuery UI sortable to automatically scroll to the bottom of the page

Having trouble with a few sortable tables and here is how I initialized the sortable object: var options = { helper: customHelper, handle: ".moveTargetDeliverables", containment: "#fieldset_deliverables_summary", tolerance: 'pointer&a ...

Exiting node.js gracefully using PM2

I have a node application running with pm2, and I need to save data before the application closes. The following code works perfectly in the shell: process.on('exit', function(){ log.debug('exit'); }); process.on('SIGINT&apos ...

What is the best way to reference a nested jQuery variable, whether global or local, within an HTML document

I've been working on this problem for days with no success. Any help would be greatly appreciated. I'm trying to call a variable from nested jQuery into HTML. The variable is named "PROBLEM". Even after trying to make it global, any updates made ...

Steps to ensure that a singular button is visible within a specific jQuery function

I am looking for a solution regarding the placement of a button labeled "add to profile" within a jQuery div. Specifically, I would like this button to only appear after the last "next" button in the sequence. For example, after question 1 and its respect ...

hiding elements yet passing down

Despite disabling the style sheet, a dynamically created form is displaying strangely. This form will show or hide various details based on selected options. For instance, many of the elements are generated with C#.net... formOutput += "<div class=&bs ...