Javascript innerHTML没有得到更新 [英] Javascript innerHTML is not getting updated

查看:93
本文介绍了Javascript innerHTML没有得到更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在尝试更新以下脚本的innerHTML

Hi I am trying to update the innerHTML of following script

<div id="global-alert-queue" class="layout-wrapper">
<div class="alert success animate-in" role="alert">
Your submission was successful.
<button id="dismiss-alert" class="dismiss" type="button"></button>
</div>
</div>

我试过以下

var cls =document.getElementById("global-alert-queue").getElementsByClassName("animate-in")[0].innerHTML = "Change Text";

但它不起作用。

推荐答案

查看内联评论:

// Run when document is completely rendered and is ready to be manipulated 
document.addEventListener("DOMContentLoaded", function () {
    document.querySelector("#global-alert-queue .animate-in").innerHTML = "Change Text";
});

演示: http://jsfiddle.net/tusharj/kg3cc4gw/3/

querySelector


返回文档中的第一个元素(使用文档节点的深度优先预先遍历遍历),与指定的选择器组匹配。 / p>

Returns the first element within the document (using depth-first pre-order traversal of the document's nodes) that matches the specified group of selectors.

更多关于 querySelector https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector

这篇关于Javascript innerHTML没有得到更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆