Assign class to another class (jQuery)

Hi guys, sorry for question, i know it may be “out of scope”. But maybe you can help me another again.

I managed to implement ScrollReveal (https://scrollrevealjs.org/) on my test site. Now want to achieve this:

There is a Heading Element. The structure is:

  • x-text-content
    – x-text-content-text
    —x-text-content-primary
    —x-text-content-subheadline

I want to assign .my-custom-class-reveal-from-top to x-text-content-primary and .my-custom-class-reveal-from-bottom to x-text-content-subheadline. How can i do this? Probably i need to use jquery to assign the class to another class?

$(’.x-text-content-text-subheadline’).addClass(‘reveal-it’); causes errors…

Hi @Georgich,

I can’t confirm assign the classes using the jQuery will work with ScrollReveal library.

But you can try with this code:

jQuery(document).ready(function($) {
	$(".x-text-content-primary").addClass('my-custom-class-reveal-from-top');
	$(".x-text-content-subheadline").addClass('my-custom-class-reveal-from-bottom');
});

Hope that helps and thank you for understanding.

Thanks! Errors have gone away. But there are no assigned classes in the code. You can check it.

No classes added…

Hi @Georgich,

There is still a js error.

Please change this code

$('.slicky').slick({
  dots: true,
  infinite: true,
  speed: 500,
  fade: true,
  cssEase: 'linear'
});

to this

jQuery('.slicky').slick({
  dots: true,
  infinite: true,
  speed: 500,
  fade: true,
  cssEase: 'linear'
});

Hope that helps

Thanks! Errors have gone away totally, but classes wasn’t added. Elements still got no classes wich i’m tring to assign.

Hi @Georgich,

The target class is incorrect. Please change the js code to this

jQuery(document).ready(function($) {
	$(".x-text-content-text-primary").addClass('my-custom-class-reveal-from-top');
	$(".x-text-content-text-subheadline").addClass('my-custom-class-reveal-from-bottom');
});

Thanks

Many thanks! A can confirm that classes were added. But ScrollReveal library won’t work dat way. It only works then classes are applied in Customize. Anyway, i want to thank you guys a lot, now i know how to assign classes that way with jQuery. It will helps me a lot in a future! MANY THANKS!

You’re always welcome Philipp!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.