the answer for all question about Oxygen Builder plugin and WordPress

Where am I going wrong with this JS?

Where am I going wrong with this JS?

// OBJECTIVE: when clicking on .ff-el-form-check which is nested within .home-section-cta, scroll down to #cta-section-1

function scrollToCta() {
var elmnt = document.getElementById(“cta-section-1″);
elmnt.scrollIntoView();
}
var object = document.getElementsByClassName(“ff-el-form-check”);
object.onclick = scrollToCta();



Source

2 Comments
  1. Robert Chan says

    getElementsByClassName returns a HTMLCollection [1]
    so when you do object.onclick you’re setting the onclick handler on the array rather than the individual elements with the class ff-el-form-check

    so you’ll have to iterate through all the elements in the object HTMLCollection and set the onclick handler for each one. like shown here:
    https://dev-notes.eu/2017/09/attach-click-event-to-many-elements-in-javascript/

    [1] https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName

  2. Gavin McIntosh says

    Hey Alex looks like you are mixing jQuery with vanilla js (which is fine) but you might aswell take advantage of jQuery selectors simply by using $(“.your-selector”) as opposed to document.getElementsByClassName or document.getElementByID.

    To get nested classes just do it how you would in CSS by wrapping $(“”) around it for example:

    $(“.class > .nested-class”)

Leave A Reply

Your email address will not be published.

Oxyrealm Docs