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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:53:57+00:00 2026-05-27T09:53:57+00:00

I am just learning how to define a function and call it back later.

  • 0

I am just learning how to define a function and call it back later.
I am stuck trying to define ‘this’ in my function without using an event.

function slide() {
    var imgAlt = $(this).find('img').attr("alt"); 
    var imgTitle = $(this).find('a').attr("href"); 
    var imgDesc = $(this).find('.block').html();  
    var imgDescHeight = $(".main_image").find('.block').height(); 

    $(.active); 
    $(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 ,
                function() { 
                    $(".main_image .block").html(imgDesc).animate({ opacity: 0.85,  marginBottom: "0" }, 250 ); 
                    $(".main_image img").attr({ src: imgTitle , alt: imgAlt}); 
                }
            );
     }
   });

On line 6 you will see ‘$(.active); ‘ and this is where I want to select the class active and then apply the following function to it. Normally I used to setting this up on a click or something so I am unsure how to impliment it.

Any help greatly appreciated! Thanks

Here is a js fiddle where you can see the big picture:
http://jsfiddle.net/wzQj6/21/

  • 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-27T09:53:58+00:00Added an answer on May 27, 2026 at 9:53 am

    See lines 3-4 in code below for how to cache your .active elements for reuse (and then use that instead of this!):

    function slide() {
    
        //cache all .active elements for reuse
        var actives = $(".active");
    
        //use the new 'actives' variable instead of 'this'
        var imgAlt = actives.find('img').attr("alt"); 
        var imgTitle = actives.find('a').attr("href"); 
        var imgDesc = actives.find('.block').html();  
        var imgDescHeight = $(".main_image").find('.block').height(); 
    
        //$(.active); -- not sure what you were doing with this :p
        $(".main_image .block").animate({ opacity: 0, marginBottom: -imgDescHeight }, 250 ,
                    function() { 
                        $(".main_image .block").html(imgDesc).animate({ opacity: 0.85,  marginBottom: "0" }, 250 ); 
                        $(".main_image img").attr({ src: imgTitle , alt: imgAlt}); 
                    }
                );
         }
       });
    

    Cheers!

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

Sidebar

Related Questions

I'm just started learning scheme and can't quite understand why this function does not
Just learning Silverlight 4/RIA and i 'm stuck in a weird problem: setup an
Im just learning mod_rewrite and regex stuff, and what I'm trying to do is
I'm just learning asp.net mvc and I'm trying to figure out how to move
I'm just learning how to do things, and want to start using some sort
Just started learning Scheme. I'm using Dr. Racket as my compiler/interpreter. I need some
I've just started learning Clojure, if I define the following map: (def distributions {:normal
I am just now learning about function pointers and, as I was reading the
Please bear with me, I'm just learning C++. I'm trying to write my header
I have recently begun learning the Win32 API using this tutorial: http://www.winprog.org/tutorial/ (though I'm

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.