Effortless pagination across various pages, utilizing diverse CSS selectors

I've integrated simple pagination into my website, but I've encountered a issue. My navigation consists of CSS tabs, each holding a unique pagination component.

Here is the jQuery pagination code snippet:

$(function(){
var perPage = 8;
var opened = 1;
var onClass = 'on';
var paginationSelector = '.pages';
$('.gallery').simplePagination(perPage, opened, onClass, paginationSelector);
});

.gallery appears to define the gallery style, and it seems that I need to repeat this code for every separate gallery.

$(function(){
var perPage = 8;
var opened = 1;
var onClass = 'on';
var paginationSelector = '.pages2';
$('.gallery2').simplePagination(perPage, opened, onClass, paginationSelector);
});

My main question is, can I streamline this code so I don't have to duplicate each jQuery call?

Another concern arises when attempting to apply the same CSS styles:

.gallery, .gallery2 {
    float: left;
    overflow: hidden;
    padding: 3px 4px 5px 6px;
    margin: 3px 4px 5px 6px;
    height: 552px;
    width:850px;
}

 .gallery, .gallery2 li {
    float: left;
    display: inline;
    font-weight: bold;
    width: 190px;
    padding: 3px 4px 5px 6px;
    background: #E6E6FA;
    border: 1px solid #999999; 
    text-align: center;
    margin: 3px 4px 5px 6px;
    font: 12px Arial, Helvetica, Sans-serif;
    color: #4c4c4c;
    height: 255px;
    -webkit-border-radius: 8px;
    -moz-border-radius: 8px;
    border-radius: 8px; 
    }

This code fails to work unless separated for each individual gallery. This means any edits require multiple adjustments. Why might this be happening?

Is this tied to the specified selection on .gallery? Is there a way to modify the code to enable selection of multiple classes?

$('.gallery').simplePagination(perPage, opened, onClass, paginationSelector);
});

Answer №1

To connect the pagination event to elements with classes gallery2 and gallery, follow these steps:

$(function(){
    var perPage = 8;
    var opened = 1;
    var onClass = 'on';
    $('.gallery').simplePagination(perPage, opened, onClass, '.pages');
    $('.gallery2').simplePagination(perPage, opened, onClass, '.pages2');
});

If you have multiple pages or variations in code structure, consider using a loop to dynamically add numbers after "gallery" and "pages". For example, appending 1, 2, 3, etc. based on your requirements.

Remember to make this last CSS change: .gallery li, .gallery2 li

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

PHP Warning: Attempt to access undefined variable

Whenever I try to insert a new record into my HTML, I keep encountering errors. I'm unsure if it's due to incorrect code on my end or if the issue lies with inserting the records. <?php $servername = "localhost"; $dbusername = "r ...

An easy way to enable mobility for BootstrapDialog on mobile devices

Currently, I am utilizing the library available at https://github.com/nakupanda/bootstrap3-dialog in order to create a dialog box. However, my issue arises when viewing the dialog on mobile devices where it exceeds the screen size. On desktops, adjusting t ...

Unable to view Mp4 video on Internet Explorer 11

My background video is in mp4 format and functions properly in Chrome, Firefox, and other browsers, but it does not work in Internet Explorer 11. To visit the website, click on "access as a non-secure site". ...

Retrieve the parent id using jQuery, not the children elements

Looking for a way to add a jQuery click event to the parent element with class .menu-option and retrieve its id, "#main-link-1", without changing the HTML structure: <div id="main-link-1" class="menu-option"> <div id="icon" class="menu-icon"> ...

There seems to be an issue preventing the Chrome browser from launching with the error message: "ERROR: connect ECONNREFUSED 127.0

My setup includes: Operating System: Windows 10 (64 bit) Browser: Chrome version 58 Node.js: 6.10.1 Npm: 3.10.10 Chromedriver: 2.29.0 After running my tests with Chrome using Selenium standalone, I encountered an error in the console where Selenium was ...

The app has crashed, currently waiting for any file changes before starting again

Can someone assist me? I am encountering an issue while trying to run npm start. The error pertains to the server.js file. [nodemon] restarting due to changes... [nodemon] starting `node server.js` /Users/johnngo/Desktop/LambdaSchool/HTTP-AJAX/server.js ...

Easily center list item numbers vertically within fixed height containers

I am facing an issue with the alignment of ordered list item numbers in a list with fixed height and vertically centered content. The numbers seem to be positioned inaccurately. li { height: 80px; border: 1px solid black; } li > span { heigh ...

Retrieving information through SELECT with a post parameter

I have created the following HTML code: <select name="compet" id="compet"></select> <select name="spage" id="spage"> <option value="home">Home</option> <option value="insert">Insert</option> <option valu ...

"Creating a new element caused the inline-block display to malfunction

Can someone explain why the createElement function is not maintaining inline-block whitespace between elements? Example problem First rectangle shows normal html string concatenation: var htmlString = '<div class='inline-block'...>&l ...

Stop Gmail from Removing Attached HTML Files

I successfully developed an HTML file with its own CSS styling and custom HEAD tags to ensure it displays well in mobile browsers. I managed to make it work with PHP as a file attachment. However, the issue arises when Gmail distorts the view of the file ...

Troubleshooting a Vue.js issue: How to fix a watch function that stops working after modifying

I have encountered a problem with my code. It seems to be working fine initially after the beforeMount lifecycle hook, but when I try to modify the newDate variable within my methods, it doesn't seem to track the changes. data() { return { ...

Executing a save function in the controller when the TinyMCE save button is clicked through an Angular directive

For the Rich text editing in my angularjs application, I am using the TinyMce angular directive. The directive is working perfectly as expected. However, I wanted to include the save plugin to enable custom save functions. To integrate the save plugin, I ...

Exploring object manipulation and generating unique identifiers by combining values - a beginner's guide

After analyzing the provided data, my goal is to come up with a method of combining the IDs and returning an array of their corresponding keys. // example data var data = [ { id: 1, key: 'a' }, { id: 1, key: 'b' }, { id: 2, key ...

Give Jquery a quick breather

My goal is to have my program pause for 3 seconds before continuing with the rest of the code. I've been researching online, but all I can find are methods that delay specific lines of code, which is not what I need. What I would like to achieve look ...

Utilizing a combination of HTML, AJAX, and PHP, transfer an HTML input array via AJAX to a PHP webpage

Despite trying numerous similar solutions, none of them have proven effective for my issue. Within a form, users can input an unspecified amount of select options that can be added as needed using AJAX. My goal is to post this array to a PHP page via AJAX ...

The functionality of an HTML form utilizing JavaScript struggles to function correctly when integrated with PHP

I created a form with JavaScript that allows me to toggle between different fields based on the selection made with radio buttons. <?php require_once 'resources/menus/adminMenu.php'; ?> <div class="col-lg-offset-3 col-lg-6 "> < ...

I'm currently attempting to determine the total cost of a series of operations, however, I am not receiving any results

Here is the code snippet from my HTML file: <tr> <td><input id="z1" type="number" oninput="calculateSubTotal()"> </td> <td>Shirts - WASH - Qty 1 to 4</td> <td>2.50 ea</td> ...

Utilize separate production environments for each client on the NodeJS server to ensure seamless operation and

After conducting extensive research, I have been unable to find a solution to my current problem. I am operating a Node server with multiple environments (dev, test, demo, prod). The server is deployed on a Linux server in the production environment via a ...

What sets array of middlewares apart from compose-middleware?

Someone recommended that I utilize the compose-middleware module in order to have an array of middlewares. After trying it out, I discovered that it works seamlessly with express.js: router.post('/editPassword', doAction ); var doAction = [ ...

Keep bootstrap content aligned to the left

I am working on creating a webpage using bulma/bootstrap and my goal is to have some text positioned on the left side of the screen. I want this text to be displayed in the red area and to stay fixed in place when I scroll down, similar to a side panel. ...