skip to Main Content

in the Divi page builder on WordPress you can add and Class or ID to a section. But I can’t figure out a way to add any inline code to the tags that the page builder then puts in the html that makes the page.

I’m trying to add the midnight.js plugin to a WordPress site using Divi and to do so I need to add inline javascript code…

<div data-midnight="white">

This is the div code that the divi builder puts on the page:

<div class="et_pb_section et_pb_section_parallax  et_pb_section_3 et_section_regular">

I need to add data-midnight="white" to the end of this code

Does anyone know a way I could do this?

2

Answers


  1. If you’re just trying to add inline code, you can use the code module that Divi provides. Just make sure you put any JavaScript inside <script> tags.

    You could try using setAttribute(). So if you’re wanting to change “div_current_id” to “date-midnight” as the ID, you could do:

    var foo = document.querySelector("div_current_id");
    foo.setAttribute("id", "date-midnight");
    
    Login or Signup to reply.
  2. If you add this in a js file that’s loaded or within a <script> tag into the HTML code, it should add the desired attribute to that element:

    $(document).ready(function() {
      $(".et_pb_section.et_pb_section_parallax.et_pb_section_3.et_section_regular").attr("data-midnight", "white");
    });
    

    It selects the element/s which has/have all those classes combined and adds the attribute with the indicated vaue to it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search