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

  • SEARCH
  • Home
  • 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 6335957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T18:57:26+00:00 2026-05-24T18:57:26+00:00

I created a button that will randomly appear on the screen (per my boss’s

  • 0

I created a button that will randomly appear on the screen (per my boss’s request) that when clicked will open an email in order to provide feedback.

My goal is to make this script do everything, mainly so I don’t have to access the ASP markup or CSS files for each website. Just throw the script in the header and place the image in the folder.

I created the script to:

  • Create a div that contains the button
  • set the CSS for the elements of that div (there will be a little image next to some text)
  • appear to the user at random

The script I came up with works fine, however, I was wondering if there was anyway I can clean this up at all. (I’m kind of new to writing my own Jquery scripts and I’m trying to learn how to be as organized as possible.)

Jquery:

$(function () {

    var fbContainer = $('<div id="feedback"><img src="image.gif" /> <a href="mailto:feedback@mywebaddress.com">Feedback</a></div>')
    .css({
        'display': 'none',
    });

    $('#header').append(fbContainer);

    $('#feedback a').css({
        'font-family': 'arial',
        'float': 'left',
        'text-decoration': 'none',
        'color':'#000000'
    });

    $('#feedback img').css({
        'float': 'left',
        'margin': '3px 5px 0 0';
    });

    var randofactor = .5;
    var randomizer = Math.random();

    if (randomizer < randofactor) {
       fbContainer.css('display', 'block');
    }

});

Thanks for any assistance

  • 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-24T18:57:26+00:00Added an answer on May 24, 2026 at 6:57 pm

    You could try encapsulating your code inside a javascript object, which I would recommend placing inside a separate file. I would suggest moving the header where the button is placed to be parametrized inside a constructor function, so you can reuse it elsewhere.

    Separating the various logical parts such as object creation and styling into their own functions also helps readability of your code.

    <script type="text/javascript">
        var randomFeedBackButton = {
            getfbContainer: function (header,feedBackAddress) {
                var fbContainer = $('<div id="feedback"><img src="image.gif" /> <a href=' + feedBackAddress + '>Feedback</a></div>')
                    .css({
                        'display': 'none'
                    });
    
                    header.append(fbContainer);
    
                return fbContainer;
            },
            generateCss: function () {
                $('#feedback a').css({
                    'font-family': 'arial',
                    'float': 'left',
                    'text-decoration': 'none',
                    'color': '#000000'
                });
    
                $('#feedback img').css({
                    'float': 'left',
                    'margin': '3px 5px 0 0'
                });
            },
            initialize: function (header) {
    
                var container = this.getfbContainer(header, "mailto:feedback@mywebaddress.com");
    
                this.generateCss();
    
                var randofactor = .5;
                var randomizer = Math.random();
    
                if (randomizer < randofactor) {
                    container.css('display', 'block');
                }
            }
        };
        $(function () {
    
            randomFeedBackButton.initialize($('#header')); /*call your script*/
    
        });
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I created a view that has a button in it that will play
I created a custom button component that accepts an array as a property. I
I have created a button CSS class that uses background images with different positions
I have a button that is programatically created, it's content is a stack panel
I have a button element that I've created like so: $submit = new Zend_Form_Element_Button('submit');
I've created an overlay that will popup whenever someone wants to upload a file
I'm trying to have a comment input field that will show the submit button
I'm writing a Java application that will have an on-screen number pad available for
Still a newbie here, forgive me. I'm trying to make a button that will
I have a button that will create a new entry (row in a table)

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.