【发布时间】:2016-07-10 10:30:21
【问题描述】:
我正在尝试检测元素中的 CSS 属性更改。我在网上搜索,发现MutationObserver javascript API。但在我的测试脚本中,它没有按预期工作(它没有提醒属性名称和属性值)。
var foo = document.getElementById("hideit");
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
alert('mutation.type = ' + mutation.type);
});
});
observer.observe(foo);
observer.disconnect();
$(function() {
$("#clickhere").on("click", function() {
$("#hideit").slideToggle('fase');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<body>
<div id="clickhere">click to toggel</div>
<div id="hideit" style="display:none;">this is the content of the hide/show toggle</div>
</body>
它显示一个 javascript 错误
TypeError: Argument 1 of MutationObserver.observe is not an object.
先谢谢了
【问题讨论】:
标签: javascript mutation-observers