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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:10:52+00:00 2026-06-13T22:10:52+00:00

I have some JQuery handling a div click. If the div is clicked once

  • 0

I have some JQuery handling a div click. If the div is clicked once it hides itself and shows another div (and posts to a php script in the background). If it is then clicked again, it’s supposed to hide the new div, show the new one again, and post more data to a different script, and so on.

It changes the first time (.f hides, .uf shows) but when I click ‘.uf’ nothing happens.

JQuery:

if($('.f').is(":visible")) {
    $('#follow').click(function() {
        var to_follow = $('.name').attr('id');
        $.ajax({  
            type: "POST",  
            url: "/bin/rel_p.php",  
            data: "y=" + to_follow,  
            success: function() {  
                $('.f').hide();
                $('.uf').show();
            }
        });
    });
}
else {
    $('#follow').click(function() {
        var to_unfollow = $('.name').attr('id');
        $.ajax({  
            type: "POST",  
            url: "/bin/relu_p.php",  
            data: "y=" + to_follow,  
            success: function() {  
                $('.uf').hide();
                $('.f').show();
            }
        });
    });
}

HTML:

            <div id="follow" class="f">
                <img src="img/icons/Follow.png">
                <h1>Follow</h1>
            </div>
            <div id="follow" class="uf" style="display:none;">
                <img src="img/icons/Unfollow.png">
                <h1>Unfollow</h1>
            </div>
  • 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-13T22:10:53+00:00Added an answer on June 13, 2026 at 10:10 pm

    use a class if you intend to use the selector twice, and don’t write the same code twice unless you have to:

    $('.follow').on('click', function() {
        var is_f = $('.f').is(":visible"),
            to_follow = $('.name').attr('id'),
            give_me_an_u = is_f?'':'u';
        $.ajax({  
            type: "POST",  
            url: "/bin/rel" + give_me_an_u + "_p.php",  
            data: {y : to_follow}
        }).done(function() {
            $('.f, .uf').toggle();
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem with slashes! I have some jQuery for handling generic dialogs
I have some jquery/php interaction set up on a page. It submits some data
I have some jQuery code that highlights a link when clicked, and changes the
I have some jQuery code that intercepts links clicked on a page: $(document).ready(function() {
I have been doing some customization to this jQuery paging script I found here
I have some jQuery code like this : $(function($) { $('input.autonumeric').autoNumeric({aSep: ',', aDec: '.',vMax:'1000000000000'});
I have some jQuery tabs on a website and I am trying to make
I have some jquery which will calculate the items in my menu and assign
I have some jquery code that is doing an ajax lookup and returning comma
I have some jquery code which I am trying to translate to YUI. I

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.