Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

182
Vistas
Can I use sweetalert2 without queryselector?

I knew SweetAlert2 when I made login features with HTML, JS, PHP, and MySQL.
so I wanted to put the SweetAlert2 alert tab when users succeeded in login, like the code below.

// user succeeded to log in and session was issued 
// ....

Swal.fire({
            icon: 'success',
            title: 'Welcome',
            text: 'You have logged in.',
    }).then(() => location.href = "../index.php");

But I encountered some errors like at the console in the developer tool in a web browser and that feature didn't work as I expected.

sweetalert2@9:1 SweetAlert2: Target parameter is not valid, defaulting to "body"
_ @ sweetalert2@9:1
we @ sweetalert2@9:1
_main @ sweetalert2@9:1
r @ sweetalert2@9:1
i @ sweetalert2@9:1
fire @ sweetalert2@9:1
(anonymous) @ loginProcess.php:6
sweetalert2@9:1 Uncaught TypeError: Cannot read properties of null (reading 'querySelector')
    at Q (sweetalert2@9:1)
    at yt (sweetalert2@9:1)
    at we (sweetalert2@9:1)
    at r._main (sweetalert2@9:1)
    at new r (sweetalert2@9:1)
    at i (sweetalert2@9:1)
    at Function.fire (sweetalert2@9:1)
    at loginProcess.php:6

Should I use the SweetAlert2 only when the user clicks some buttons? If not, I want how to use SweetAlert2 without users' event triggering. Please let me know about this.

Thank you.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda