javascript - DOM 元素存在,jQuery 无法操作它

标签 javascript jquery css meteor

我有这个事件处理程序,我可以记录 DOM 元素,但我不能用它做任何事情。设置显示或任何内容都没有任何效果。

 Template.layoutTemplate.events({
   'mouseover .top_nav_button': function(ev){
    ev.preventDefault();


    console.log($(this).css('padding'));

    $(this).css('display', 'none');

}

});

模板代码如下:

<template name = 'layoutTemplate'>
    <div id = 'top_nav'>
        {{> loginButtons}}
        <a class='top_nav_button' id = 'about_snipex_button' href="{{pathFor 'about'}}">About Snipex</a>
        <a class='top_nav_button' id = 'become_verified_button' href="{{pathFor 'verified'}}">Become Verified!</a>
        <a class='top_nav_button' id = 'terms_button' href="{{pathFor 'terms'}}">Terms&Conditions</a>
    </div>
    <h1 id='layout_header'><a id = 'home_button' href="{{pathFor 'home'}}">snippetExchange</a></h1>
    <div id='layout_header_row_2'>
        <h2 id='layout_by_line'><a id = 'home_button' href="{{pathFor 'home'}}">valuable answers</a></h2>
    </div>
    <div id='sub_nav'>
        <a class='sub_nav_button' id = 'notifications_button' href="{{pathFor 'notifications'}}">notifications</a>
        <a class='sub_nav_button' id = 'my_history_button' href="{{pathFor 'user_profile' _id=currentUser}}">my history</a>
        <a class='sub_nav_button' id = 'new_post_button' href="{{pathFor 'new_post'}}">new post</a>
    </div>
    {{> yield}}
</template>

最佳答案

display 规则没有值作为hidden

将其更改为 $('#top_nav').css('display', 'none');

Hidden是css中visibility规则的属性。

关于javascript - DOM 元素存在,jQuery 无法操作它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30384564/

相关文章:

javascript - 使用 Javascript 对象将元素添加到 JSON 表示法

javascript - 在多个 div 上拉伸(stretch)图像

javascript - 同步 .each 与异步 .ajax

javascript - 带有 JSON 内容的 DropDown 浮出控件

javascript - 使用单个下拉更改事件更新多个 AmChart 的数据集

javascript - 以非线性方式从一个数快速计数到另一个数

javascript - 使用 jQuery 从 HTML 解析时间数据

html - CSS 媒体查询相互覆盖

javascript - jQuery 如果表中存在特定文本隐藏他行的第一个 td

javascript - $window.innerHeight 在 chrome 和 firefox 中返回不同的值