PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, September 8, 2022

[FIXED] how to change follow button from follow to following with jquery

 September 08, 2022     ajax, html, javascript, jquery, php     No comments   

Issue

i created a following system in my website, and i have a follow button that is similar to twitter or facebook. when i click the follow button i want it to change to following and stays that way until the user clicks again. i tried doing this with jquery but so far i am struggling with making it work.

here is what i tried.

my jquery code:

 $(document).ready(function(){              

 $("#follow-button").click(function(){
  if ($("#follow-button").text() == "Follow"){
    $("#follow-button").text() == "Following";

}else{


 }
}); 
});

my html code:

     <button id="follow-button" class='msg-icon' name="follow" type="submit" >Follow    
            <input type="hidden" value="<?php echo $_GET['search']; ?>" name="follow_id"/>
        </button>

how will i go about doing this, and what am i missing?


Solution

when you get button text in include space first you remove space using trim() function and button change text using to text() in pass your text

                $(document).ready(function(){
                    $("#follow-button").click(function(){
                        if ($("#follow-button").text().trim() == "Follow"){
                            $("#follow-button").text('Following');
                        }else{
                            $("#follow-button").text('Follow');

                        }
                    });
                });


Answered By - Paras Raiyani
Answer Checked By - Cary Denson (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing