如何使用jQuery在Wordpress中隐藏一个div,并在隐藏另一个div时显示它?

时间:2019-10-19 13:42:41

标签: php jquery html wordpress

这不起作用。默认情况下,应该隐藏#autoverkocht,除非隐藏.b-car-info__price,否则应显示#autoverkocht。

jQuery(document).ready(function($){
$("#autoverkocht").css({   
    display: "none",
    visibility: "hidden"
});
})

if($('.b-car-info__price').is(":hidden")){


      $('#autoverkocht').css('visibility', 'visible');
}

上面的jQuery或下面的functions.php代码不起作用。

add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
    wp_enqueue_script(
    'your-script', // name your script so that you can attach other scripts and de-register, etc.
    get_template_directory_uri() . '/js/autoverkocht.js', // this is the location of your script file
    array('jquery') // this array lists the scripts upon which your script depends
);

}

2 个答案:

答案 0 :(得分:0)

您可以使用以下内联样式:

<div id='autoverkocht' style='display: none;'>
</div>

或使用如下CSS样式:

#autoverkocht{
  display: none;
}

然后在jquery中执行以下操作:

<script>
  jQuery(document).ready(function($){ 
    if($('.b-car-info__price).is(":hidden")){
      $('#autoverkocht').show();        
    }
  });

</script>

答案 1 :(得分:0)

您需要jQuery togglehide

$('#autoverkocht').hide()
$('#autoverkocht, .b-car-info__price').on(
  'click',
 function() 
 {
   $('#autoverkocht, .b-car-info__price').toggle()
 }
);

希望这就是您所需要的……