I have a post index page.
On clicking the a given post's show comment button, the comments of the post get visible. This is easy since I can use
this
find
//open hidden post comments and replies in post thread
$(document).on('click', '.open-all-post-comments', function (event) {
var post_id = $(this).data('pid');
var all_replies = $('#post_' + post_id).find('.post-comment-replies:has(.post-comment-reply)');
all_replies.show();
$(this).closest('.open-all-post-comments-row').hide();
});
//checking all posts on the page and show the dropdown if user is the post author
$(document).on("page:change", function() {
if ($('.post-container').length > 0) {
if ($('.edit-post-dropdown-button').data('postauthorid') == $('#bodycurrentuser').data('currentuserid')) {
$('.edit-post-dropdown-button').removeClass('hidden');
};
};
});
<div class="panel panel-default post-panel" id="post_<%= post.id %>">
........
<li class="dropdown edit-post-dropdown-button hidden" data-postauthorid ="<%= post.user_id%>">
......
</li>
</div>
Try to iterate through each post.I could not test it but something like this should work:
$( '.post-panel' ).each(function( index ) {
if ($(this).find('.edit-post-dropdown-button').data('postauthorid') == $('#bodycurrentuser').data('currentuserid')) {
$(this).find('.edit-post-dropdown-button').removeClass('hidden');
}
});