Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
DIVI, trying to get reference to mobile menu using JS - undefined

The Problem

I'm using the DIVI theme and am simply attempting to get a reference to the mobile menu's ul element (this has a class of 'et_mobile_menu'). Up until now I've not had any issues getting references in javascript, but this particular one always seems to be undefined/null.

What I've attempted

I tried it in a setTimeout and it worked (it found the element with no problems). So, I tried it using:

document.addEventListener('DOMContentLoaded', function() {
    let el = document.querySelector('.et_mobile_menu');
});

This didn't work. So I gave onload a try:

window.onload = function() {
    let el = document.querySelector('.et_mobile_menu');
}

Again, this didn't work so I tried using JQuery like this...

$(document).ready(function () {
    let el = document.querySelector('.et_mobile_menu');
});

Now this did work... every time the reference was valid.

More Information

I'm using a simple DIVI child theme which I created, and my javascript file is being enqueued in the footer. I've specified 'jquery' as a dependency and have tried add_actions() with different priorities. (I've also tried this with getElementsByClassName())

Summary

I'm curious, is there something specific with Wordpress that I'm missing or is there more I can do to pinpoint the reason the JQuery 'ready' function works here but the vanilla JS methods don't?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda