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 949895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:28:34+00:00 2026-05-15T23:28:34+00:00

First click: empty floatymessage div. second click and after: works. jQuery: function floatymessage(message){ var

  • 0

First click: empty floatymessage div. second click and after: works.

jQuery:

function floatymessage(message){
    var box = $j(".floatymessage")
    if (box.length == 0) {
        $j('body').append("<div class='floatymessage'></div>");
    }
    box.html(message);
    // center it
    box.css("left", ( $j(window).width() - box.width() ) / 2+$j(window).scrollLeft() + "px");
    box.fadeIn('slow');

    setTimeout(function(){$j('.floatymessage').fadeOut('slow');},3500);
}

link:

<a href="#" onclick="floatymessage('Asking questions is not allowed.');"></a>

css for floatymessoge:

div.floatymessage {
    position: absolute;
    top: 20%;
    width: 300px;
    height: 50px;
    background: black;
    color: white;
    text-align: center;
    filter:alpha(opacity=75);
    -moz-opacity:0.75;
    -khtml-opacity: 0.75;
    opacity: 0.75;
    box-shadow: 10px 10px 5px #000;
    border: 1px solid black;
    border-bottom-left-radius: 5px 5px;
    border-bottom-right-radius: 5px 5px;
    border-top-left-radius: 5px 5px;
    border-top-right-radius: 5px 5px;
    line-height: 50px;
    z-index: 10000;
    display: none;
}
  • 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-05-15T23:28:35+00:00Added an answer on May 15, 2026 at 11:28 pm

    Your logic with box was missing a step, if it is not already in the dom you need to set your variable ‘box’ to the new div:

    if (box.length == 0) {
      box = $j("<div class='floatymessage'></div>");
      $j('body').append(box);
    }
    

    further,

    You can use the method you have setup but when using an anchor tag to fire a javascript event you need to add a return false to stop it from processing it like a normal link.

    <a id="mine" href="#" onclick="floatymessage('msg');return false;">run</a>
    

    It is a better practice to bind events in this case:

    $j("#mine").click(function() { floatymessage('msg'); });
    

    You could achieve the same effect using a span tag instead of an anchor tag that wants to navigate to a url.

    <span id="mine" onclick="floatymessage('msg');">run</span>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my jquery code: $('input').click(function(){ $('h1').empty().queue(function(){ console.log('queue'); }); }); }); Only the first
i'm using this jquery script: $(document).ready(function(){ $(#basketItemsWrap li:first).hide(); $(.productPriceWrapRight a img).click(function() { var productIDValSplitter
The first .click function is used to add an element(div) in a container and
Here is my js: $('ul li div').hide(); $('ul li a').click(function(){ var nextUp = $(this).next();
first my code: var form = $(#form_usr);//An empty div to load an html fragment
Hey guys here is my code: <script>$('td#view-details').click(function() { var fg = $(this).closest('td').siblings(':first-child').text(); $('#'+fg+'confirm').click(function ()
When I click on the button, the first time, everything works fine, but the
<script type=text/javascript> $(function() { $(#continue).click(function () { $.ajax({ type: POST, url: dbc.php?check=First, data: {full_name
$(function(){ $(.mailbutton).click(function() { var email = $(.mailingfield).val(); $.post(/PHP_scripts/mailinglist.php, { email: email }, function(data) {
I have the following in a plug-in script: $(#menu) .on('click','a[href^=/Test]',function(event){ event.preventDefault(); var href =

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.