jquery - 隐藏div问题

标签 jquery

我有一个 div,我打算像这样隐藏:

$("#bla").hide();

直到一些 jQuery 代码用数据填充它。这似乎打破了“填充代码”。隐藏仍应允许“填充代码”访问 HTML,还是我遗漏了某些内容?

最佳答案

是的,隐藏 div 仍然允许在其中“填充代码”。

来自doc

This is roughly equivalent to calling .css('display', 'none'), except that the value of the display property is saved in jQuery's data cache so that display can later be restored to its initial value.

您所做的基本上只是告诉网页不要显示您的元素。它仍然是 DOM 的一部分。您可以访问它的 html 等。您可以使用 .show 稍后显示

例如:

var elem = $("#bla");
elem.hide();//hides the element
elem.text("Hello World");//sets its inner text to "Hello World"
elem.show(); // "Shows the element again"

这是另一个关于 how hide/show is implemented 的有趣问题

关于jquery - 隐藏div问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15243995/

相关文章:

javascript - 如何将键盘事件绑定(bind)到 div 元素?

javascript - 在加载时以编程方式调用页面顶部的 anchor 标记

javascript - 在 .match() 上使用\和/

javascript - 我可以在拖动图像/元素时将其转换为另一个图像/元素的最简单方法是什么?

javascript - 加载时崩溃时网站 javascript 出错

javascript - 将 marginLeft 更改为滚动父 div 中的子 div

javascript - 在 jquery 对话框中打开现有屏幕

jquery - html导航菜单如何突出显示所选菜单

javascript - 修复了知道 CSS 中导航栏的部分?

jquery - 使用 jQuery 延迟显示 ajax 加载 gif