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

  • Home
  • SEARCH
  • 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 8165513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:33:24+00:00 2026-06-06T19:33:24+00:00

I have this code for displaying content for login and registration in my PHP

  • 0

I have this code for displaying content for login and registration in my PHP file:

<?php // LOGIN PART ?>
<div class="login-part"></div>

<?php // REGISTRATION PART ?>
<div class="registration-part"></div>

And this in my js file:

$(document).ready( function() {
            // FOR REGISTRATION
            $('span.logreg.reg').click(function () {

                $('div.registration-part').append('<p>Registration</p>');
            });

            // FOR LOGIN
            $('span.logreg.log').click(function () {

                // insert html
                $('div.login-part').append('<p>Login</p>');
            });
        });

Now, everytime I click on a span it shows the text login or registration, according to which of the span was clicked.

Thats OK, however I need to add it only once, so when the user click more times on the span it will be not adding more text.

Remove() or empty() is not an option, as far as I know, because I need the information inside input boxes (there will be input boxes later for inserting user info) to stay there and not be deleted if the user click accidentally on the span again.

It can however delete the html inside the div, if he clicks on another span. E.g. if span.log is active, after clicking on span.log nothing happens, but if he clicks on span.reg the html inside div.login-part will be removed and registration text will appear.

How to do something like this?

  • 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-06T19:33:27+00:00Added an answer on June 6, 2026 at 7:33 pm

    Try APi: .one please : (Reading your question it seems you only need to append the HTML like login once using .one will resolve this issue)

    Attach a handler to an event for the elements. The handler is executed
    at most once per element.

    APi link: http://api.jquery.com/one/

    This way append will only one time as desired and you will not have duplicate html showing multiple times.

    Hope this helps, please lemme know if I missed anything,

    further bit diff demo: http://jsfiddle.net/avSDa/9/ using .is(:empty) which ever suits you.

    code like this

      $('span.logreg.log').one('click', function () {
    
                    // insert html
                    $('div.registration-part').append('<p>Login</p>');
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 pages, say page1.html and page2.html. page1.html has this code: $(document).ready(function() {
I have this code: $(div[id^='intCell']).mouseover(function() { $(this).css({ border:,1px solid #ff097c}); }).mouseout(function() { $(this).css({border:,1px solid
I have this code snippet: <div id=div1> </div> <div id=div2> <h3>This is the content</h3>
I have written php script for user login but instead of displaying the result
I have this code structure: public abstract class ContentEntryBase { public string UniqueIdentifier; public
I have this bit of code <input type=image src=/wp-content/themes/happy/images/add-to-cart.png name=Buy class=wpsc_buy_button id=product_<?php echo wpsc_the_product_id();
I have this code for doing an ajax request to a webservice: var MyCode
I have this code to show a map using the Virtual Earth API: <script
I have this code here, which is intended to allow any type of arguments:
I have this code in my forms.py : from django import forms from formfieldset.forms

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.