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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T00:01:17+00:00 2026-06-19T00:01:17+00:00

Alright lets see if I can describe this. I have a handful of functionality

  • 0

Alright lets see if I can describe this.

I have a handful of functionality that was created sometime ago, and works swimmingly. However there is a new desired spec, so without having to rewrite the code base in a matter of speaking, and without having to double up on code to pull the same effect off I am trying to figure out how I can go about making something jump back higher in the code within the same function to repeat the run of the function rather then doing the same code again below.

What I have is a click based triggers ie:

$('.selector').click(function(){});

In this function is about 30 lines of functionality to create a new element and populate it accordingly. However unfortunately in that same bit of functionality there is conditions to wether it should or not.

*The previous requirement was when the element it creates is open and populated just throw an alert() saying essentially wrap up what your doing, and then go on to the next.

*Now the new requirement is just close that and open a new element.
Which I’ve gotten to close out the existing, and do everything I want it to do, except the population of the new element which is above where the condition is currently.

Knowing there is no “go to” type of logic in javascript (or last I knew). the only thing I can think of is taking the same code from above and putting it in the condition as well, doubling up on the code and having litterally 2 copies of the same bit. I want to avoid that, but cant think of a way to do it. So here I am looking for ideas

  • 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-19T00:01:18+00:00Added an answer on June 19, 2026 at 12:01 am

    Knowing there is no “go to” type of logic in javascript (or last I
    knew). the only thing I can think of is taking the same code from
    above and putting it in the condition as well, doubling up on the code
    and having litterally 2 copies of the same bit. I want to avoid that,
    but cant think of a way to do it. So here I am looking for ideas

    Why don’t you just pull this piece of code out into a function? You can run the function if the conditional is true in the original instance, and run it all the time in your callback? This is fairly minimal refactoring, just move the code out of the logic into a separate function, keeping it as is and maybe making some of the referenced variables into parameters.

    So something like this if you want to run all the actions regardless of the conditional statements:

    ...
    if(condition){
      actionA();
    }
    if(condition2){
      actionB();
    }
    ...
    
    $('.selector').click(function(){
        actionA();
        actionB();
    });    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright lets say I have a cPlayer class that inherits from cOrganism , which
Alright. Lets say i have a UITextField where a user can input an url
Alright, let's say I have a table that looks like this: ID | DATE
Alright I don't see why this isnt working. It seems pretty simple. Here is
Alright so i need to open a .txt file that will be created in
Alright so I have no idea how to even begin doing this But basically
Alright I created some custom classes for my project sourced from this tutorial ,
Alright so I have been looking around (on SO and Google) to see if
Alright so lets say I have these files in vendor/assets/javascript/ : modernizer.js lightbox.js highchart.js
Alright so I have a custom page template designed with javascript and php (lets

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.