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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T14:14:11+00:00 2026-05-23T14:14:11+00:00

I have 2 live events need to change the background color whether the user

  • 0

I have 2 live events need to change the background color whether the user click the button on .padd or .paddc. First button is working, the background can be change but not the second button. What wrong with the code with jQuery?

<a id="hms" href="1" onClick="adduser('1'); return false;"><img id="t1" class="padd" src="tta/addr.png"></a>
    <a id="hms2" href="2" onClick="validateuser('2'); return false;"><img id="te2" class="paddc" src="tta/addr.png"></a>


$(document).ready(function(){
    var ffd = "0";
    $(".padd").live('click',function(event){
        //update profile - remove pending
        $.ajax({
            type: "POST",
            cache: "false",
            url: "pendingupd.php?pid="+event.target.id,
            success: function(aaa) {
            var ttf= "#t" + event.target.id;
                if(aaa=="Approved"){
                    $(ttf).css("background","url('tta/pass.png') 50% 50px no-repeat");
                    $(ttf).css("background-color","#ffffda");
                } else {
                    $(ttf).css("background","none");
                    $(ttf).css("background-color","none");
                }
                if(aaa=="Error"){
                    $(ttf).css("background-color","#f0b7b7");
                }
            }
        });
    });
    $(".paddc").live('click',function(event2){
        //update profile - remove pending
        $.ajax({
            type: "POST",
            cache: "false",
            url: "pendingupd.php?pid="+event2.target.id,
            success: function(aaa2) {
            var ttf2= "#te" + event2.target.id;
                if(aaa2=="Approved"){
                    $(ttf2).css("background","url('tta/pass.png') 50% 50px no-repeat");
                    $(ttf2).css("background-color","#ffffda");
                } else {
                    $(ttf2).css("background","none");
                    $(ttf2).css("background-color","none");
                }
                if(aaa2=="Error"){
                    $(ttf2).css("background-color","#f0b7b7");
                }
            }
        });
    });
});
  • 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-23T14:14:11+00:00Added an answer on May 23, 2026 at 2:14 pm

    The only difference between the two functions is that the first function has var ttf= "#t" + event.target.id; while the second has var ttf2= "#te" + event2.target.id; This leads me to believe that the issue is probably in the DOM. Are you sure everything has the right ID? Are those really supposed to be different?

    Either way, a shorter version of that code might look like this:

    $(document).ready(function(){
        var ffd = "0";
        // jQuery lets you select more than one element.
        // combining them makes what you intend more obvious.
        // and it means you create fewer functions.
        $(".padd, .paddc").live('click',function(event){
            var ttf= $(this).hasClass( ".paddc" )? "#t": "#te" ;   
            //update profile - remove pending
            $.ajax({
                type: "POST",
                cache: "false",
                url: "pendingupd.php?pid="+event.target.id,
                success: function(aaa) {      
                    // replace this with ttf = "#t" if te was a typo.
                    updatePendingState( aaa, ttf + event.target.id );
                }
            });
        });
    });
    // there is no point in having this as something created 
    // EVERY time that an AJAX call is made (the old way).
    function updatePendingState( aaa, selector )
    {
        // initialize values to defaults.
        var bgColor = "none", bgImg = "none";
        if(aaa=="Approved"){
            // update if a change is merited.
            bgColor = "url('tta/pass.png') 50% 50px no-repeat";
            bgImg = "background-color","#ffffda";
        } else if(aaa=="Error"){
            bgColor = "#f0b7b7";
        }
        // grab the value once and use it multiple times. Why wast function calls?
        var ttf = $(selector);
        ttf.css("background",bgImg);
        ttf.css("background-color",bgColor);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Bind multiple events to jQuery 'live' method I have the following function:
I have this js code: $(#startSearch).live(click, function(event) { $(input:checkbox[name='searchId']:checked).each(function() { var searchId = $(this).val();
I am loading content into a page with ajax that will have live click
I have the following code: $(document).ready(function () { $(tr).live('click',function(){ alert(TR); }); $(input).live('click',function(){ alert(INPUT); });
I have a click function that has a popup window that I need to
I need to capture the keyup event to provide live validation when user is
I have two input fields that need to hide when first visit. There will
i have the following block of code: $(#contact_container form, #contact_details form).live( submit, function(event) {
I have live tiles in my app and is not a web service app.
I have live data in a database i want to tweet data in real

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.