Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

181
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!