Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8885041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:12:44+00:00 2026-06-14T21:12:44+00:00

I have a problem with alert messages. It is displayed normally, and I can

  • 0

I have a problem with alert messages. It is displayed normally, and I can close it when the user presses x (close), but when the user tries to display it again (for example, click on the button event) then it is not shown. (Moreover, if I print this alert message to console, it is equal to [].) My code is here:

 <div class="alert" style="display: none">
   <a class="close" data-dismiss="alert">×</a>
   <strong>Warning!</strong> Best check yo self, you're not looking too good.
 </div>

And event:

 $(".alert").show();

P.S! I need to show alert message only after some event happened (for example, button clicked). Or what I am doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:12:45+00:00Added an answer on June 14, 2026 at 9:12 pm

    Data-dismiss completely removes the element. Use jQuery’s .hide() method instead.

    The fix-it-quick method:

    Using inline javascript to hide the element onclick like this:

    <div class="alert" style="display: none"> 
        <a class="close" onclick="$('.alert').hide()">×</a>  
        <strong>Warning!</strong> Best check yo self, you're not looking too good.  
    </div>
    
    <a href="#" onclick="$('alert').show()">show</a>
    

    http://jsfiddle.net/cQNFL/

    This should however only be used if you are lazy (which is no good thing if you want an maintainable app).

    The do-it-right method:

    Create a new data attribute for hiding an element.

    Javascript:

    $(function(){
        $("[data-hide]").on("click", function(){
            $("." + $(this).attr("data-hide")).hide()
            // -or-, see below
            // $(this).closest("." + $(this).attr("data-hide")).hide()
        })
    })
    

    and then change data-dismiss to data-hide in the markup. Example at jsfiddle.

    $("." + $(this).attr("data-hide")).hide()
    

    This will hide all elements with the class specified in data-hide, i.e: data-hide="alert" will hide all elements with the alert class.

    Xeon06 provided an alternative solution:

    $(this).closest("." + $(this).attr("data-hide")).hide()
    

    This will only hide the closest parent element. This is very useful if you don’t want to give each alert a unique class. Please note that, however, you need to place the close button within the alert.

    Definition of .closest from jquery doc:

    For each element in the set, get the first element that matches the selector by testing the element itself and traversing up through its ancestors in the DOM tree.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following problem. The alert allways returns undefined, but I know it
I have the following HTML: <div class=alert-message success> <a class=close style=display: none; >×</a> <p>Authenticated
I have the following problem: <script type=text/javascript> alert(1. ČĆŽŠĐčćžšđ); </script> <script type=text/javascript src=Tst.js></script> <script
I have problem SIMILAR to preventing form data reposting, but not quite the same
Hy guys. I've implemented Google Cloud Messaging in my app,but i have a problem
How can i display an alert message or alert box when getting the information(not
I have registered ProximityAlert in MapActivity. No problem with catching alerts in BroadcastReceiver and
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This
I have problem with repopulating form_upload after validation. Other input fields or selectboxes are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.