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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:38:46+00:00 2026-05-25T21:38:46+00:00

I have this function that is suppose to change the html of a span.

  • 0

I have this function that is suppose to change the html of a span. It works the first time but anyclick after that it doesn’t change anything. I know the query is working because the database is updating. Here’s the code.

$('#availabilityicon').click(function() {
    $.ajax({
            type: "GET",
            url: "includes/changeavailability.php",
            success: function(msg) {
                    if(msg === "available") {
                            var vailspan = $('span#avail').html('<a id="availabilityicon" href="#"><img align="center" width="16px" height="16px" src="images/available.png" /></a>');
                    }
                    else if(msg === "unavailable") {
                            var availspan = $('span#avail').html('<a id="availabilityicon" href="#"><img align="center" width="16px" height="16px" src="images/unavailable.png" /></a>');
                    }
            }
    });
});

here is the php code

<?php
session_start();
$user = $_SESSION['username'];
include("dbcon.php");
$result = mysql_query("SELECT availability FROM user WHERE username='$user' ORDER BY id DESC") or die(mysql_error());
$row = mysql_fetch_assoc($result);
$availability = $row['availability'];
if($availability == 'yes') { 
$query = mysql_query("UPDATE user SET availability='no' WHERE username='$user'") or die(mysql_error());
echo "unavailable"; 
}
elseif($availability == 'no' or $availability == "") { 
$query = mysql_query("UPDATE user SET availability='yes' WHERE username='$user'") or die(mysql_error()); 
echo "available"; 
}
mysql_close($con);
?>
  • 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-05-25T21:38:46+00:00Added an answer on May 25, 2026 at 9:38 pm

    There’s a spelling mistake in your javascript, you’ve put vailspan where you probably meant to put availspan after the if(msg === "available") { line.

    If it’s not that, try changing the click event to a live one:

    $('#availabilityicon').live('click', function() {
    

    just in case your javascript is overwriting that the #availabilityicon icon element and failing to re-attach the event to the new one

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

Sidebar

Related Questions

I have this function that switches the HTML contents from one element on a
I have this function called ProperCase that takes a string, then converts the first
I have this function in my Javascript Code that updates html fields with their
I have this function that prints the name of all the files in a
I have this function that converts all special chars to uppercase: function uc_latin1($str) {
I have this function that takes the input of a, runs a calculation and
So I have this function that forks N number of child processes. However it
I have this function in jQuery that gets data from a page with POST,
I have this function on my controller (Im using CodeIgniter) that reads the database,
I have this function to edit all fields that come from the form and

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.