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)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.