-2

I have a simple script that calls my onepage-scroll.js script. How can I set the class name for div (which is a container) in case of this script? I've broke my head of trying to solve this problem - unfortunately my javascript knowledge is too poor at the moment and I'd appreciate any help.

jQuery(".main").onepage_scroll({
   sectionContainer: "div",     
   easing: "ease",               
   animationTime: 1000,             
   pagination: true,                
   updateURL: false,                
   beforeMove: function(index) {},  
   afterMove: function(index) {},   
   loop: false,                     
   keyboard: true,                  
   responsiveFallback: false,                        
   direction: "vertical"
});
Jamdev
  • 562
  • 1
  • 3
  • 19
  • one_page_scroll function should return a jquery object on which you can call further functions. – anuragb26 Dec 04 '18 at 11:27
  • 1
    jQuery(".main").addClass("className") – anuragb26 Dec 04 '18 at 11:27
  • the `.onepage_scroll() ` refers to this [plugin/lib](https://github.com/peachananr/onepage-scroll/blob/master/jquery.onepage-scroll.js) – DarkMukke Dec 04 '18 at 11:28
  • It is expected you do a little searching / research before posting a question. A simple search for your title will produce hundreds of duplicates. If you have tried to add a class and failed, you should show that code and explain why it didn't work – Pete Dec 04 '18 at 11:32

2 Answers2

3

You can also try this:

let a = document.getElementsByClassName("main");
a.classList.add("class-name");

To understand the classList concept you can check here: https://developer.mozilla.org/en-US/docs/Web/API/Element/classList

Suprabha
  • 535
  • 4
  • 8
  • I wondering why this is the accepted answer, the OP is already using jQuery on that element, might as well chain / use it again – DarkMukke Dec 04 '18 at 12:33
1

As mentioned by @anuragb26 in the comments, it is not the purpose of onepage scroll to do that.

You could extend the plugin because internally the element is accessible through this.el but the easiest solution is just to do it separately with

jQuery(".main").addClass("className")
DarkMukke
  • 2,469
  • 1
  • 23
  • 31