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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:37:22+00:00 2026-06-09T21:37:22+00:00

I am trying to make an object named Dialogo . The idea is create

  • 0

I am trying to make an object named Dialogo. The idea is create it some functions and then call them inside of another method itself. Take a look:

function Dialogo(tamano){
    this.tamano = tamano;

    this.cerrar = function(){
        $('#dialogo_fondo').remove();
    };

    this.mostrar = function(){
        var dialogo_fondo = $('<div>').attr({id: 'dialogo_fondo' });
        $('body').fadeIn("slow", function(){$(this).append(dialogo_fondo);});
        $('#dialogo_fondo').css( {"width": $(window).width(), "height": $(window).height()});
        $('#dialogo_fondo').click(function(){ 
            this.cerrar(); 
        });
    };  
}  

Using jquery 1.7.2. According to the code, when I do click over #dialogo_fondo element, it should be removed, because the cerrar() method was triggered in click event. But it does not work. Can you point me to the right direction?

  • 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-09T21:37:23+00:00Added an answer on June 9, 2026 at 9:37 pm

    this in mostrar declaration points to the anonymous function instance, check it with console.log(this);. So you need to create another reference to outer object var that = this; and use it instead:

    function Dialogo(tamano){
        var that = this; // <--- here is the magic
    
        this.tamano = tamano;
    
        this.cerrar = function(){
            $('#dialogo_fondo').remove();
        };
    
        this.mostrar = function(){
            var dialogo_fondo = $('<div>').attr({id: 'dialogo_fondo' });
            $('body').fadeIn("slow", function(){$(this).append(dialogo_fondo);});
            $('#dialogo_fondo').css( {"width": $(window).width(), "height": $(window).height()});
            $('#dialogo_fondo').click(function(){ 
                that.cerrar(); // <---- use "that", not "this"
            });
        };  
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a call to api which returns json object {
I am trying to make a very simple object rotate around a fixed point
I am trying to make asynchronous calls using xmlhttprequest object so it completely works
I'm trying to make getJSON to use JSONP object, but I can't figure out
I'm trying to make a copy constructor for an object and one of the
I'm trying to make a copy function and add it to the object's prototype.
I'm trying to make a deep copy of an object, including a GregorianCalendar instance.
I'm trying to make this code generic: public final Object unwrap(Class arg0) { throw
I'm trying to make a genric code to serialize and deserialize any object that
I'm trying to make a list containing different objects. List<Object> list = new ArrayList<Object>();

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.