Incorrect horizontal scrolling within a jQuery div container

I have implemented a plugin for horizontal scrolling on my website. You can check out the plugin here.

Here is the demo link showcasing the plugin in action:

However, I am encountering an issue where the pages do not scroll when the link to scroll is placed within multiple divs. For example:

<div>
    <div>
        <hr />
        <a href="#top">&larr; Back to start</a> <a href="#" rel="next">Next section &rarr;</a>
    </div>
</div>

The plugin utilizes the following script:

<script>
    (function($) {
        $(window).load(function() {

            /* Page Scroll to id fn call */
            $("#navigation-menu a,a[href='#top'],a[rel='m_PageScroll2id']").mPageScroll2id({
                layout: "horizontal",
                highlightSelector: "#navigation-menu a"
            });

            /* demo functions */
            $("a[rel='next']").click(function(e) {
                e.preventDefault();
                var to = $(this).parent().parent("section").next().attr("id");
                $.mPageScroll2id("scrollTo", to);
            });
        });
    })(jQuery);
</script>

If anyone has advice or solutions to help me resolve this problem, I would greatly appreciate it. Thank you.

Answer №1

Instead of repeatedly using .parent(), consider traversing up through the ancestors of the clicked element:

$("a[rel='next']").click(function(e){
    e.preventDefault();
    var to=$(this).closest("section").next().attr("id");
    $.mPageScroll2id("scrollTo",to);
});

Answer №2

I believe you may be making a mistake. Try using the same class for each tag and I am confident it will function properly. Refer to the plugin documentation for further assistance.

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

Error: Trying to use 'Player' before it has been initialized

Recently, I have been utilizing ES6 syntax along with import/export on Nodejs using the ESM module loader. Everything was running smoothly until I encountered an error related to imports. Below are the error messages that popped up: joseph@InsaneMachine ...

Guide on converting jQuery code to AngularJS

Implementing Quantity Increment and Decrement Operations for Multiple Rows in AngularJS 1.x with ng-repeat Struggling to translate jQuery code into AngularJS? Here's a comparison between jQuery and AngularJS implementations for quantity increment and ...

How can you fetch data from a PHP file using AJAX before performing a header redirect?

I am currently in the process of adding more dynamism to my website. I have developed a forum from scratch and now I am integrating JavaScript into it. All the PHP backend work is complete. My next goal is to enable user login without having to refresh the ...

Learn the process of generating dynamic rows in HTML

Currently, I'm working on a website where I am incorporating the Flipkart API to display a list of products. However, the products are not appearing in the well-formatted view that I had designed. Specifically, I want only 4 products to show per row b ...

placing a div inside another div

As I work on my website, I have created several panels with a repeating texture. To enhance the visual appeal of the site, I decided to add colored divs and adjust opacity for a tint effect instead of using separate images. The issue I'm facing is th ...

Implementing flickity with bootstrap 4 to create a seamless horizontal scrolling experience for cards that adjusts to different

Could anyone share a sample of successfully implementing flickity inside bootstrap 4? I am attempting to create a horizontal list of cards in a carousel format, where I can scroll through three at a time. I found using flickity intriguing, but I've en ...

Adding 'foobar' to innerHTML using JQuery

I want to add new content instead of removing the existing one. I have been using the element.innerHTML += 'foobar' method for this purpose, but now I am trying to learn how to use jQuery. I came across the $().html('') function, but it ...

Issue with ReactJS and Material UI: FlexGrow functionality malfunctioning

I'm currently grappling with the implementation of FlexBox, particularly in understanding how to effectively utilize flexGrow. Despite my efforts, I haven't been able to achieve the desired result as the background appears to only wrap around the ...

What is the best library to utilize for uploading an Excel file in a React application?

As a beginner in JS and React, I have a simple question that I hope someone can help me with! I am trying to figure out how to upload an excel file using a form and then extract the data from the rows and columns. For example, I would like to calculate th ...

Redux-form fails to retrieve the value of the SelectField

I'm trying to work with a simple form using react and redux-form. My goal is to gather all the field values from my form and send them to my RESTful API using jQuery ajax. Unfortunately, I've run into an issue where redux-form doesn't seem ...

Why does the scrollbar appear even when the inner element is smaller in CSS transformation?

Please check out this link .wrapper { width: 200px; height: 200px; padding: 10px; border: 1px solid #888; overflow: auto; } .scale { width: 400px; height: 300px; background-color: red; transform: scale(0.4); transform-origin: 0 0; transitio ...

Utilizing class variables for animations in Angular 7 component

Currently, I am facing an issue with an animation that is supposed to expand the height on hover. The problem arises because the height of the label is auto-generated and does not animate properly with just the :hover selector. Below is a snippet from my T ...

"Utilize a specific parameter in the npm run script for enhanced

Is it possible to pass a named parameter to an npm run script in order to achieve the following functionality? "scripts":{ "say-hello":"echo $greeting && ls" } npm run hello --greeting=hello The desired outcome is to replace the $greeting ...

Encountering a 404 error for a JSONP Get request while deploying on IIS

When utilizing jquery AJAX with datatype jsonp, everything runs smoothly on my local development environment even with a large amount of data. However, once deployed on IIS, it only functions properly for requests shorter than 2121 characters; anything mor ...

Is it possible to combine margin auto with a transform on the left simultaneously?

While examining a webpage, I noticed a positioning issue and decided to remove some CSS code to determine the root of the problem. It appears that the navbar has a 1px gap on the left side from the edge of the screen. After removing the last two lines of c ...

A Great Option for Easy Drag and Drop Functionality

Currently researching options for Drag and Drop functionality with items such as images and textareas. Need a solution that provides coordinates of where the item is dropped on screen, saves it, and allows placement in the exact same location later. Desir ...

Sending auth0 token as a parameter in $http.get request in Angular

I am encountering difficulties when trying to attach the auth0 token to a http.get request for an API that requires the token. The token is generated upon user login and stored in the browser's local storage, which is functioning properly. The challen ...

Incorporate audio playback on image click using JavaScript, with the feature to automatically pause the playback if multiple images are playing simultaneously

<img class="cl" src="photo/198.jpg"/></br> <audio class="cs" controls> <source src="audio/198 banu nagamothu.mp3" type="audio/mpeg"> </audio> I prefer not to have audio controls initially, but when the image i ...

Issue with CSS animations not functioning correctly within React application

Currently in the process of creating a basic dice roller and aiming to incorporate a spin animation for added visual interest. Strangely, the animation only triggers on the first roll and not on subsequent attempts (unless I refresh the page). Here is the ...

Experiment with re-rendering advertisements using Vue.js

Hey there, I'm new around here so please be patient with me if I make any mistakes :D So, onto my question! I have a website built with vuejs and I want to incorporate some ads into it. To do this, I have created some components: <template> ...