-1

I was looking to implement the helpful answer here but it isn't working for me in my browser or even in the code snippet here but works in jsfiddle http://jsfiddle.net/joydh7L0/2/

Basically the alert is always shown and the script doesn't seem to be working. Am a beginner so might be missing something very obvious. Any help appreciated!

Update: Based on a couple of comments on this I am using bootstrap and with that using their recommended jQuery link. Thanks!

"https://code.jquery.com/jquery-3.4.1.slim.min.js"

<!doctype html>
<html lang="en">

  <head>
  </head>
  <body>
    <button type="submit" class="btn btn-primary">Submit</button>

    <div class="alert alert-success" id="submitsuccess"   role="alert"> Thanks for letting us know!</div>
    <script>
      $(document).ready(function() {
        $(".alert").hide()
        $("button").click(function showAlert() {
          $(".alert").fadeTo(2000, 500).slideUp(500, function() {
            $(".alert").slideUp(500);
          })
        })
      })
    </script>
  </body>

3
  • What if you change '$(".alert").slideUp(500);' (the last one) to 'console.log("Hi");'. Can you see something on the developer console and if yes then when? Commented May 6, 2020 at 21:40
  • Which version of jQuery are you using? Commented May 6, 2020 at 21:42
  • unfortunately changing to console.log("Hi") doesn't seem to do anything. Commented May 6, 2020 at 22:01

1 Answer 1

0

Make sure you have included Jquery plugin.

 <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

also if using css framework like booststrap you can also include.

Sign up to request clarification or add additional context in comments.

7 Comments

I am using bootstrap and have included the standard bootstrap recommendation <script src="code.jquery.com/jquery-3.4.1.slim.min.js"
Here created sample check the html part, that you can run locally as well.
@user13448168 were you able to solve with above resources?
Thanks yes this worked. The two problems were, the default bootstrap jQuery link was "..slim.min.js" - with the slim version this did not work. And second, my jQuery plugin was declared at the bottom of the html file. When I moved it up (and used min.js) it worked. Many thanks for the help.
@user13448168 if you wish you can like/vote my answer and comments. It will be great help. Thank you!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.