how to delete the virtual dom that created in memory using js
how to delete the virtual dom that created in memory using js
const virtualDomConvert = (filename = ``) => {
const svg = document.querySelector(`[id="live_map_svg"]`);
const clone = svg.cloneNode(true);
clone.id = 'vdom_svg';
// autoRemoveAttributes(clone);
const html = clone.outerHTML;
// add xml namespace, support browser open preview
const xml = `
<?xml version="1.0" encoding="UTF-8"?>
${html}
`.trim();
const alink = document.createElement('a');
alink.setAttribute('href', 'data:image/svg+xml;charset=utf-8,' + encodeURIComponent(xml));
alink.setAttribute('download', filename);
alink.style.display = 'none';
const vdom = document.createElement(`div`);
vdom.appendChild(alink);
alink.click();
vdom.removeChild(alink);
// ??? how to delete vdom ???
// document.body.appendChild(alink);
// alink.click();
// document.body.removeChild(alink);
}
solution
object delete
vdom = document.createElement(`div`);
// <div></div>
vdom.remove();
// undefined
vdom;
// <div></div>
window.vdom;
// <div></div>
this.vdom;
// <div></div>
delete this.vdom;
// true
vdom;
// VM98286:1 Uncaught ReferenceError: vdom is not defined at <anonymous>:1:1
vdom = document.createElement(`div`);
// <div></div>
vdom.setAttribute("id", "uuid_div");
//undefined
document.getElementById("uuid_div");
//null
document.getElementById("uuid_div").remove();
//VM105598:1 Uncaught TypeError: Cannot read property 'remove' of null
at <anonymous>:1:36
demo
not work
https://developer.mozilla.org/en-US/docs/Web/API/Node/removeChild
// remove child
node.removeChild(child);
// OR
const oldChild = node.removeChild(child);
https://developer.mozilla.org/en-US/docs/Web/API/ChildNode/remove
// remove self
node.remove();
Web Component
https://developer.mozilla.org/en-US/docs/Web/API/Document/createElement#Web_component_example
https://developer.mozilla.org/en-US/docs/Web/API/HTMLUListElement
https://www.w3.org/TR/custom-elements/
https://github.com/w3c/webcomponents/
refs
https://www.digitalocean.com/community/tutorials/how-to-make-changes-to-the-dom
xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
how to delete the virtual dom that created in memory using js的更多相关文章
- React v16-alpha 从virtual dom 到 dom 源码简读
一.物料准备 1.克隆react源码, github 地址:https://github.com/facebook/react.git 2.安装gulp 3.在react源码根目录下: $npm in ...
- Virtual DOM(八)
Virtual DOM 这个概念相信大部分人都不会陌生,它产生的前提是浏览器中的 DOM 是很“昂贵"的,为了更直观的感受,我们可以简单的把一个简单的 div 元素的属性都打印出来,如图所示 ...
- vue的Virtual Dom实现- snabbdom解密
vue在官方文档中提到与react的渲染性能对比中,因为其使用了snabbdom而有更优异的性能. JavaScript 开销直接与求算必要 DOM 操作的机制相关.尽管 Vue 和 React 都使 ...
- 将你的 Virtual dom 渲染成 Canvas
项目概述 一个基于Vue的virtual dom插件库,按照Vue render 函数的写法,直接将Vue生成的Vnode渲染到canvas中.支持常规的滚动操作和一些基础的元素事件绑定. githu ...
- 简单说明 Virtual DOM 为啥快
Virtual DOM 就是用 JS 的对象来描述 DOM 结构的一个 DOM 树.如: var element = { tagName: 'ul', // 节点标签名 props: { // DOM ...
- virtual DOM的作用:将DOM的维护工作由系统维护转交给virtual DOM维护
virtual DOM的作用:将DOM的维护工作由系统维护转交给virtual DOM维护 两个方面:对应用端 & 对DOM端(渲染准备的计算) 1.将DOM状态的维护工作由系统维护转交给vi ...
- React Virtual DOM Explained in Simple English
If you are using React or learning React, you must have heard of the term “Virtual DOM”. Now what is ...
- React virtual DOM explained in simple English/简单语言解释React的虚拟DOM
初学React,其中一个很重要的概念是虚拟DOM,看了一篇文章,顺带翻译一下. If you are using React or learning React, you must have hear ...
- 窥探Vue.js 2.0 - Virtual DOM到底是个什么鬼?
引言 你可能听说在Vue.js 2.0已经发布,并且在其中新添加如了一些新功能.其中一个功能就是"Virtual DOM". Virtual DOM是什么 在之前,React和Em ...
随机推荐
- Java——序列化与反序列化
序列化 序列化 序列化是什么 如何实现对象序列化 实战练习 Serializable 反序列化 总结 使用Reader读取文件内容1 使用Reader读取文件内容2 序列化是什么? 将对象的状态存储到 ...
- 小白搭建WNMP详细教程---MYSQL安装与设置
MYSQL的安装请参考WAMP中的mysql的安装教程,两者是一样的. https://www.cnblogs.com/missbye/p/12050312.html
- VSCode-Prettier和ESLint如何和睦共处?
1 在VSCode中单独使用Prettier保存代码自动格式化的配置方法 1.1 为什么要使用Prettier? 手动调整代码格式,不仅低效,而且在团队协作开发中,无法保证代码风格统一,所以需要引入自 ...
- 弱网测试之Fidder
是用Fidder可以模拟若罔测试. 1.Fiider设置 fiddler中选中Rules->Cutomize Rules,在文件中搜索关键字:m_SimulateModem: 修改m_Simul ...
- Codeforces Round #533 (Div. 2) A. Salem and Sticks(枚举)
#include <bits/stdc++.h> using namespace std; int main() { int n;cin>>n; int a[n];for(in ...
- UVALive 7146
Long long ago there is a strong tribe living on the earth. They always have wars and eonquer others. ...
- JavaScript——匿名函数和闭包
匿名函数就是没有名字的函数 闭包就是一个函数中的另一个函数 函数可以不加分号,但是语句要加!! 可以把匿名函数的返回值赋值给变量!! box()时返回里面的函数,再加一个()就会返回里面那函数的值(浅 ...
- Codeforces Round #670 (Div. 2) B. Maximum Product (暴力)
题意:有一长度为\(n\)的序列,求其中任意五个元素乘积的最大值. 题解:先排序,然后乘积能是正数就搞正数,模拟一下就好了. 代码: int t; ll n; ll a[N]; int main() ...
- CQRS+Event Sourcing
using System; using System.Collections.Generic; using System.Linq; namespace CQRS { public class Eve ...
- SpringBoot 中使用 Swagger2 出现 whitelabel page error 解决方法
今天使用Swagger最新版,在pom.xml引入 <dependency> <groupId>io.springfox</groupId> <artifac ...