- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 native Javascript。通过 insertAdjacentHTML
添加新元素后,我想选择该元素本身( <div id="two">two</div>
)。如何在不搜索 DOM 的情况下获得它?
// <div id="one">one</div>
var d1 = document.getElementById('one');
d1.insertAdjacentHTML('beforeend', '<div id="two">two</div>');
// At this point, the new structure is:
// <div id="one">one<div id="two">two</div></div>
最佳答案
根据文档
https://developer.mozilla.org/en-US/docs/Web/API/Element/insertAdjacentHTML
'之前'
在元素的最后一个子元素之后插入新元素 Just。因此使它成为新的最后一个 child 。
您可以在 d1 元素上使用 lastChild。
var d1 = document.getElementById('one');
d1.insertAdjacentHTML('beforeend', '<div id="two">two</div>');
console.log(d1.lastChild)
<div id="one">one</div>
关于javascript - 在 insertAdjacentHTML 之后选择相同的新元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41448382/
我正在用 Java 编写代码,并且使用 Vaadin 8 扩展。 我有一个 Vaadin 组合盒,效果很好。但我不仅想从组合框中选择项目,还想选择书面输入。这意味着我想使用组合框作为下拉菜单以及文本编
我正在尝试将 AJAX 添加到 JQuery ListView 中并呈黄色闪烁,但我似乎无法使其正常工作。谁能指出我正确的方向? http://jsfiddle.net/zFybm/ 最佳答案 根据
我有这个样式表: .pixel{ position: absolute; height: 10px; width: 10px; background-color: #f
这是我用来将新行推送到容器的一行代码: this.$el.append(new ItemView(item).render().el); 其中item是Backbone.js model,render
我正在尝试在 anguar.js 中制作一些测试应用程序,但遇到了问题。我的 js 文件包含: live = angular.module('live',[]); live.controller('p
如何绑定(bind)页面加载后创建的新元素? 我有这样的东西 system = function() { this.hello = function() { alert
html5 新元素(页眉、导航、页脚等)在 IE 中不工作 最佳答案 您需要包含 HTML5 shiv 脚本以允许在旧版 IE 浏览器中设置 HTML5 元素的样式:http://code.googl
我是一名优秀的程序员,十分优秀!