how to add next & previous button between the variants or options?

can any one help me to add next

&previous button between options like in this website product page.

Pet Portraits - Custom Illustrated from your Digital Photos – West & Willow

Hey @jahin2 ,

To integrate “Next” and “Previous” buttons between options as shown in your HTML snippet, you can modify it to display the buttons and allow the user to switch product options (like color or size). Below is an approach that adds “Next” and “Previous” buttons to cycle through the options between the product variants.

Step 1: Update HTML for Buttons

Your HTML code for the “Next” button is already in place. We just need to add a “Previous” button and adjust the overall structure.

Here’s how you can update it:


  

    

      Subtotal:
      
        Rs. 6,700.00
      
    

    

Free shipping over $100

  

  
    
    
  

  
    
  

Step 2 : CSS Styling

The buttons are already styled with classes, but you can refine the styles as needed:

.product-option-navigation {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
}

.prev-option,
.next-option {
  background-color: #f5f5f5;
  border: 1px solid #ccc;
  padding: 10px 20px;
  cursor: pointer;
  font-size: 14px;
  transition: background-color 0.3s;
}

.prev-option:hover,
.next-option:hover {
  background-color: #e5e5e5;
}

Step 3 : JavaScript for Product Option Navigation

Next, you need JavaScript to enable switching between the product options when either the “Previous” or “Next” button is clicked. This will simulate the option change (e.g., color or size) by adjusting the selection on the product variant selector.

document.addEventListener('DOMContentLoaded', function () {
  var prevButton = document.querySelector('.prev-option');
  var nextButton = document.querySelector('.next-option');
  var productOptions = document.querySelector('.single-option-selector'); // Adjust this to target your actual product option select
  var selectedIndex = 0;

  // Handle Previous Button Click
  prevButton.addEventListener('click', function () {
    if (selectedIndex > 0) {
      selectedIndex--;
      productOptions.selectedIndex = selectedIndex;
      productOptions.dispatchEvent(new Event('change')); // Trigger change event
    }
  });

  // Handle Next Button Click
  nextButton.addEventListener('click', function () {
    if (selectedIndex < productOptions.options.length - 1) {
      selectedIndex++;
      productOptions.selectedIndex = selectedIndex;
      productOptions.dispatchEvent(new Event('change')); // Trigger change event
    }
  });
});

Step 4 : Integrate and Test

  • Product Option Select : Ensure you target the correct element for your product options (like color, size, etc.) in the JavaScript (single-option-selector in the example above). This might need to be adjusted based on your theme.

  • Testing : After adding this code, test your product page to ensure the “Next” and “Previous” buttons cycle through the available options properly.

Let me know if you need further customizations or help with integrating this into your theme!

If I was able to help you, please don’t forget to Like and mark it as the Solution!
If you’re looking for expert help with customization or coding, I’d be delighted to support you. Please don’t hesitate to reach out via the email in my signature below—I’m here to help bring your vision to life!

Best Regard,
Rajat Sharma

@jahin2
Sorry you are facing this issue,
It would be my pleasure to help you.
Please share your site URL,
I will check out the issue and provide you with a solution here.

also please mention your requirement what is functionality for if user client for next button?

Hi,

Thanks for the reply.

But unfortunately i don’t have any knowledge in coding and stuff. can you please help me i detail.

so do i need to put these codes in theme—edit code.

https://itqdte8prkxvyc2b-90656506170.shopifypreview.com

@jahin2 thanks for url yes its can be done some customization code