I have the following button that is used to View More Friends in increments of 16:
<button class="cancel auto-btn hide-btn" id="viewAllFriends" style="display: visible;">View All Friends</button>
It's initial display is given with this:
var username = '<?php echo $username; ?>';
var num_friends = '<?php echo $num_friends; ?>';
var counter = 8;
$(document).ready(function(){
<?php if ($num_friends > 8): ?>
$("viewAllFriends").attr('style', 'display: visible;');
$("#viewAllFriends").click(function(){
counter = counter+16;
$.ajax({
url:'includes/handlers/ajax_load_profile_friends.php',
type:'POST',
data:{'username':username, 'num_friends':num_friends, 'counter':counter},
success: function(data) {
$('#data_friends').html(data);
}
});
});
<?php else: ?>
$("#viewAllFriends").attr('style', 'display: none;');
<?php endif; ?>
});
The button displays if a user has more than 8 friends or does not if there is less than 8. When ajax_load_profile_friends.php gets to the end, I have a hidden tag that echos on the page.
$max = "<p id='max' hidden>$num_rows</p>";
echo "$max";
The html output looks like this: <p id="max" hidden="">43</p>
This hidden tag doesn't appear on the page until the last query. What I'm trying to do, is when 43 appears (which in this example indicates that there are no more friends to load) is remove the View More friends button from view.
This is what I've tried:
var friend_count = '<?php echo $num_friends; ?>';
var max = ("max").text();
if (max = friend_count) {
$("#viewAllFriends").remove();
}
Sadly this isn't working - the button remains. Everything else works fine, but this final detail. I'm not so great at jQuery, so I'm wondering if the ajax is overriding this script, or if I'm possibly not getting the data in var max? Any help, links, examples would be appreciated.
maxcount and test (if (max = friend_count) {, etc)?When ajax_load_profile_friends.php gets to the end, I have a hidden tag that echos on the pagemeans, exactly? How does themaxelement get added to the page? Can you edit your question and show that code?ajax_load_profile_friends.phpand now being echoed onto the page in last query with$max = "<input id='max' type='hidden' value='$num_rows'>";echo "$max";The html value on the page is displaying as 43.datapassed to your AJAX success handler?datain success handler. It appears on the page ONLY in the last query which is an additional indicator that it's working correctly. It's also displaying the correct number. I just want to grab it andhide()the button somehow.