如何在html值更改后运行函数

时间:2017-12-20 12:21:47

标签: javascript jquery html

我正在做一个简单的悬停滚动条项目。当有人通过prepend(),append(),html()等更改html标签中的内容时,我想更改拇指的高度。我怎样才能做到这一点?我用Google搜索并找到了像

这样的答案
$('.class').html('value').trigger(somefunction())

但这不是答案。因为我不是其他js代码的开发者。我只想用我的脚本文件来做这件事。

这是我的项目: - https://github.com/rameshkithsiri/hoverscroll

1 个答案:

答案 0 :(得分:1)

以下是这样做的方法,您可以使用DOMSubtreeModified个事件。但请注意It before using it.

$("body").on('DOMSubtreeModified', ".myCLASS", function() {
   alert($(this).html());
});
setTimeout(function(){ $(".myCLASS").html("my Test") }, 3000);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>


<div class="myCLASS"></div>