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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:41:33+00:00 2026-06-15T07:41:33+00:00

I have what I hope is a very simple question. In fact I think

  • 0

I have what I hope is a very simple question. In fact I think it’s silly I haven’t figured it out. I have an example of my code here:

http://jsfiddle.net/joeljoelbinks/pVSDL/

excerpt:

function lighten() {

jQuery(this).css('opacity', '0.5');
jQuery(this).html('DO IT!');
}

function darken() {

jQuery(this).css('opacity', '1');
jQuery(this).html('CLICK TO EXPAND');
}

function expand() {

jQuery(this).off('click', expand);
jQuery(this).off('mouseover', lighten);
jQuery(this).on('click', contract);
darken(); //this doesn't get called
jQuery(this).animate({width: '200px', height: '200px'}, 500);

}

function contract() {

jQuery(this).off('click', contract);
jQuery(this).on('mouseover', lighten);
jQuery(this).on('click', expand);
lighten(); //this doesn't get called
jQuery(this).animate({width: '100px', height: '100px'}, 250);

}

This is a simplified prototype of an expanding div design I am implementing on a website I am working on. Everything works as designed except the lighten() and darken() functions do not get called when inside the expand() or contract() functions. I have tried multiple ways to call them from within the functions but they don’t work. Notice that I left them there just to show you that that’s what needs to be fixed. How do I get them to fire when within the expand/contract functions? They work as when bound to mouseover/mouseout events which I coded at the beginning, but not within the other function. If I make them execute an alert() function, then they work in all contexts but not if I am trying to modify JQuery(this) with them.

Bonus question: also, look at the top of the js: how do I bind both variables to the same events as opposed to the current code where I have to bind them separately? I have tried bind() and several other things but I can only get them to bind when I do them separately which is a violation of DRY principles 😉

  • 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-15T07:41:35+00:00Added an answer on June 15, 2026 at 7:41 am

    You need to make sure that this refers to the right thing:

    darken.call(this);
    

    instead of

    darken();
    

    The value of this is determined upon every function call, so you need to make sure that it’s correct by using .call(). Alternatively, you could change your darken() and lighten() functions so that they took a parameter for the element to affect.

    edit — as to your “bonus”, you can’t do that without some other function to “serialize” the calls to the two event handlers you need to bind to “click” (or whatever). That’s certainly possible, but it’s questionably valuable. You could always just write a single function to call the two functions in question (again being careful to explicitly pass on this appropriately).

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

Sidebar

Related Questions

I have, what I think/hope, is a very simple PHP question. I have made
I hope I am not missing something very simple here. I have done a
I'm trying to learn WPF, so here's a simple question, I hope: I have
I have a -as I hope- very simple question: how to disable an UISearchBar
I have a very simple question I hope someone can answer as I start
Very simple question I hope. I have the usual <select> box like this <select
I have a very simple (rather stupid) question, I hope someone can clear my
Hope you are fine. I have to make a Web Project (very simple) I
i have what i hope is a quick question about some code i am
I have what I hope is a fairly simple question about using the value

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.