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

标签 javascript jquery html

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

$('.class').html('value').trigger(somefunction())

但这不是答案。因为我不是其他js代码的开发者。我想仅使用我的脚本文件来执行此操作。

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

最佳答案

这是这样做的方法,您可以使用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>

关于javascript - 如何在html值更改后运行函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47905984/

相关文章:

javascript - 导航属性不会刷新

JQuery 验证 addClassRules

javascript - jQuery 选择器优化

html - 设置为 css attr 字段数据标题的问题,来自 javascript 的 id

javascript - 在 youtube API 上禁用全屏 - javascript

javascript - 如何将 SVG 节点转换为 PNG 并将其下载给用户?

javascript - 动态更改表中一行的 CSS 类

html - 第二个导航栏位于顶部的第一个导航栏下方

html - 在 Django 服务器端访问 HTML 数组输入字段值时出现问题

javascript - 如何使用 "Enter" key 提交 SAPUI5 SimpleForm?