我目前正在尝试显示一个隐藏按钮,该按钮仅在单击链接时显示,但是我不确定在链接不存在时如何显示它。
(function ($) {
$(document).ready(function()
{
$('.wp-block-file.aligncenter a').click(function(e)
{
$('.learndash_mark_complete_button').removeClass('hidden');
});
});
})(jQuery);
<div class="wp-block-file aligncenter"><a href=".pdf" target="_blank" rel="noreferrer noopener" class="customize-unpreviewable">Open PDF</a></div>
<input type="submit" value="Mark Complete" class="learndash_mark_complete_button hidden">
答案 0 :(得分:1)
您可以检查link元素的 length ,以将类添加到该元素:
if(!$('.wp-block-file.aligncenter a').length){
$('.learndash_mark_complete_button').removeClass('hidden');
}
演示:
if(!$('.wp-block-file.aligncenter a').length){
$('.learndash_mark_complete_button').removeClass('hidden');
}
.hidden{
visibility: hidden;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="submit" value="Mark Complete" class="learndash_mark_complete_button hidden">