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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:38:58+00:00 2026-05-27T11:38:58+00:00

Hi Im new to programming jQuery and i have a quick code snippet that

  • 0

Hi Im new to programming jQuery and i have a quick code snippet that I would love someone to test for me.

I think it works well.. but i dont know if its the best way to handle it.

working example: http://jsfiddle.net/zWnLv/29/

//hide wrapper at document ready
        $('#newsbox_content_wrapper').hide();

        //toggle visiblility of newsbox and slide down to scroll window to newsbox
        $('.newsbox_toggle').bind('click', function () {
            //define speed for effect
            var $speed = 400;

            //check to see if the class 'open' exists then run
            if ($('.newsbox_toggle').hasClass('open')) {
                //scroll to the top of the newsbox
                $('html, body').animate({scrollTop: $('#header_lower').offset().top}, $speed);
                $('#newsbox_content_wrapper').slideDown($speed);
                $('.newsbox_toggle').removeClass('open');
                //delay HTML replacement to sync with animation
                $('.newsbox_expand').delay($speed).queue(function(n) {
                    $(this).html('Click to Close News Feature.');
                    $(this).addClass('rotate');
                    n();
                });
            } else {
                //scroll back to top of body
                $('html, body').animate({ scrollTop: 0 }, $speed);
                $('#newsbox_content_wrapper').slideUp($speed);
                $('.newsbox_toggle').addClass('open');
                //delay HTML replacement to sync with animation
                $('.newsbox_expand').delay($speed).queue(function(n) {
                     $(this).html('Click to Read More.');
                     $(this).removeClass('rotate');
                     n();
                });
            }
        });
  • 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-27T11:38:59+00:00Added an answer on May 27, 2026 at 11:38 am

    The only way you could “optimize” this is using callbacks instead of manually delaying functions. .slideUp() and .slideDown() accept callbacks to be executed after the animation finishes.
    Using chaining is a best practice, so you don’t have to recreate objects (see the callback functions).

    Also, I’ve changed the bind() function with the new on(), which was added in jQuery 1.7.

    $('.newsbox_toggle').on('click', function () {
        //define speed for effect
        var $speed = 400;
    
        //check to see if the class 'open' exists then run
        if ($('.newsbox_toggle').hasClass('open')) {
            //scroll to the top of the newsbox
            $('html, body').animate({scrollTop: $('#header_lower').offset().top}, $speed);
            $('#newsbox_content_wrapper').slideDown($speed, function() {
                $('.newsbox_expand').html('Click to Close News Feature.').addClass('rotate');
            });
            $('.newsbox_toggle').removeClass('open');
        } else {
            //scroll back to top of body
            $('html, body').animate({ scrollTop: 0 }, $speed);
            $('#newsbox_content_wrapper').slideUp($speed, function() {
                $('.newsbox_expand').html('Click to Read More.').removeClass('rotate');
            });
            $('.newsbox_toggle').addClass('open');
        }
    });
    

    If you’re on jQuery < 1.7, use .click(), which is a shorthand for .bind().

    $('.newsbox_toggle').click(function () {
        // ...
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to jQuery and javascript programming. I have a program below
hello I am new here and in programming as well. Today I have been
let's say that you in your new programming work your boss comes and says
I always believed that when starting to learn a new programming language programmer must
I'm very new to jquery and programming in general but I'm still trying to
I'm very new to web programming and jQuery. I want to load images and
I am a bit new to programming in jQuery/Javascript and am having some issues
Doing some code in JavaScript/jQuery and I need to have it where the user
I have an interesting idea for a new programming language. It's based on a
I'm super new to programming, I currently have a table of venues which can

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.