DOM Manipulation

Creating Elements

// IE 5.5+
document.createElement('div');

Inserting Elements Before & After

// IE 4+
document.getElementById('1')
.insertAdjacentHTML('afterend', '<div id="1.1"></div>'); // IE 4+
document.getElementById('1')
.insertAdjacentHTML('beforebegin', '<div id="0.9"></div>');

Inserting Elements As Children

// IE 4+
document.getElementById('parent')
.insertAdjacentHTML('afterbegin', '<div id="newChild"></div>'); // IE 4+
document.getElementById('parent')
.insertAdjacentHTML('beforeend', '<div id="newChild"></div>')

Moving Elements

// IE 5.5+
document.getElementById('parent')
.appendChild(document.getElementById('orphan')); // IE 5.5+
document.getElementById('parent')
.insertBefore(document.getElementById('orphan'), document.getElementById('c1'));

Removing Elements

// IE 5.5+
document.getElementById('foobar').parentNode
.removeChild(document.getElementById('foobar'));

Adding & Removing CSS Classes

// All modern browsers, with the exception of IE9
document.getElementById('foo').classList.add('bold'); // All browsers
document.getElementById('foo').className += 'bold'; // All modern browsers, with the exception of IE9
document.getElementById('foo').classList.remove('bold'); // All browsers
document.getElementById('foo').className =
document.getElementById('foo').className.replace(/^bold$/, '');

Adding/Removing/Changing Attributes

// IE 5.5+
document.getElementById('foo').setAttribute('role', 'button'); // IE 5.5+
document.getElementById('foo').removeAttribute('role');

Adding & Changing Text Content

// IE 5.5+
document.getElementById('foo').innerHTML = 'Goodbye!'; // IE 5.5+ but NOT Firefox
document.getElementById('foo').innerText = 'GoodBye!'; // IE 9+
document.getElementById('foo').textContent = 'Goodbye!';

Adding/Updating Element Styles

// IE 5.5+
document.getElementById('note').style.fontWeight = 'bold';

no-jquery 02 DOM的更多相关文章

  1. Unit01: jQuery概述 、 jQuery选择器 、 jQuery操作DOM

    Unit01: jQuery概述 . jQuery选择器 . jQuery操作DOM 使用jQuery放大字体: <!DOCTYPE html> <html> <head ...

  2. 抛弃jQuery:DOM API之操作元素

    原文链接:http://blog.garstasio.com/you-dont-need-jquery/dom-manipulation/ 我的Blog:http://cabbit.me/you-do ...

  3. 抛弃jQuery:DOM API之选择元素

    原文链接:http://blog.garstasio.com/you-dont-need-jquery/selectors/ 我的Blog:http://cabbit.me/you-dont-need ...

  4. jQuery的DOM操作详解

    DOM(Document Object Model-文档对象模型):一种与浏览器, 平台, 语言无关的规则, 使用该接口可以轻松地访问页面中所有的标准组件DOM操作的分类 核心-DOM: DOM Co ...

  5. 解密jQuery内核 DOM操作

    jQuery针对DOM操作的插入的方法有大概10种 append.prepend.before.after.replaceWith appendTo.prependTo.insertBefore.in ...

  6. jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解

    jQuery操纵DOM元素属性 attr()和removeAtrr()方法使用详解 jQuery中操纵元素属性的方法: attr(): 读或者写匹配元素的属性值. removeAttr(): 从匹配的 ...

  7. jQuery介绍 DOM对象和jQuery对象的转换与区别

    jQuery介绍 DOM对象和jQuery对象的转换与区别 jQuery介绍      jQuery: http://jquery.com/      write less, do more.   j ...

  8. jquery和dom之间的转换

    刚开始学习jquery,可能一时会分不清楚哪些是jQuery对象,哪些是DOM对象.至于DOM对象不多解释,我们接触的太多了,下面重点介绍一下jQuery,以及两者相互间的转换. 什么是jQuery对 ...

  9. jQuery操作Dom、jQuery事件机制、jQuery补充部分

    jQuery操作Dom: 修改属性: //使用attr()方法 //attr(name, value) //name:要修改的属性的属性名 //value:对应的值 //attr方法,如果当前标签有要 ...

  10. web进阶之jQuery操作DOM元素&&MySQL记录操作&&PHP面向对象学习笔记

    hi 保持学习数量和质量 1.jQuery操作DOM元素 ----使用attr()方法控制元素的属性 attr()方法的作用是设置或者返回元素的属性,其中attr(属性名)格式是获取元素属性名的值,a ...

随机推荐

  1. 【leetcode】Substring with Concatenation of All Words (hard) ★

    You are given a string, S, and a list of words, L, that are all of the same length. Find all startin ...

  2. 【2016-10-11】Linux系统常用的关机或重启命令shutdown、reboot、halt、poweroff、init 0及init 6的联系与区别

    Linux下常用的关机/重启命令一般包括: shutdown.reboot.halt.poweroff等,当然了我们可以使用init 运行等级runlevel 0即halt来关机,或使用init 运行 ...

  3. September 4th 2016 Week 37th Sunday

    The morning crowned the humble cloud with splendor. 晨光为谦逊的白云披上壮丽的光彩. Humility is a virtue. Many famo ...

  4. Cityengine, 3ds MAX, FME

    Cityengine 和 3ds MAX 一次只可以导入 (import) 一个模型. FME可以一次导入多个模型,因此可以用它来进行数据整合,然后放到cityengine里头去现实.FZViewer ...

  5. 查询Oracle中字段名带"."的数据

    SDE中的TT_L线层会有SHAPE.LEN这样的字段,使用: SQL>select shape.len from tt_l; 或 SQL>select t.shape.len from ...

  6. Hadoop组件之-HDFS(HA实现细节)

    NameNode 高可用整体架构概述 在 Hadoop 1.0 时代,Hadoop 的两大核心组件 HDFS NameNode 和 JobTracker 都存在着单点问题,这其中以 NameNode ...

  7. php 分页查询

    get方法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  8. Ubuntu开机自启动

    http://www.jb51.net/os/Ubuntu/181138.html http://blog.csdn.net/elim051/article/details/6173367

  9. C#dynamic关键字(1)

    一.object,var,dynamic的区别 static void Main() { //var是C# 3中引入的,其实它仅仅只是一个语法糖. var本身并不是一种类型, 其它两者object和d ...

  10. 如何使用Case进行简单判断

    Case具有两种格式.简单Case函数和Case搜索函数. --简单Case函数 CASE sex ' THEN '男' ' THEN '女' ELSE '其他' END --Case搜索函数 ' T ...