Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 当某个类在页面上时,如何使DIV出现?_Jquery_Drupal_Hide_Show - Fatal编程技术网

Jquery 当某个类在页面上时,如何使DIV出现?

Jquery 当某个类在页面上时,如何使DIV出现?,jquery,drupal,hide,show,Jquery,Drupal,Hide,Show,我正在使用Drupal CMS。在Drupal中有一个messages DIV,其类为。message 出现错误时,类“error”将添加到消息DIV 在我的页面上,我有一个DIV,它有一个类“指令” 我希望此DIV被隐藏,并且仅在错误类可见时显示 这是我的密码: (function ($) { $(document).ready(function () { $(".instruction").hide; }); if ($('.messages').

我正在使用Drupal CMS。在Drupal中有一个messages DIV,其类为
。message
出现错误时,类
“error”
将添加到消息DIV

在我的页面上,我有一个DIV,它有一个类
“指令”
我希望此DIV被隐藏,并且仅在错误类可见时显示

这是我的密码:

 (function ($) {
    $(document).ready(function () {
        $(".instruction").hide;
    });

    if ($('.messages').hasClass('error')) {
    $('.instruction').show;
    }

})(jQuery);

然而,它似乎不起作用。我怎样才能让它工作?谢谢你的帮助

这是一个函数调用,您需要像这样添加
()

$.ready(function() {
    $(".instruction").hide();

    if ($(".messages").hasClass("error")) {
        $(".instruction").show();
    }

});
(从HTML中删除“错误”以查看它是否正常工作)