By element.appendChild(newNode), let's talk about _javascript skills
May 16, 2016 pm 07:23 PMIn the element.appendChild(newNode) method, if newNode itself is a node in Dom, then the appendChild method performs an append operation no longer
, but a move operation. For example:
[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
Because btn1 itself is in dom A node, so the appendChild operation will move btn1 to the back of btn4 instead of copying it.
Using this feature, we can achieve alternative text seamless scrolling with a very small amount of code.If you need to introduce external Js, you need to refresh to execute
]
Haha, isn’t it very simple? Well, I posted this method on CSDN in May this year, and it aroused a lot of discussion among JavaScript enthusiasts
. The post was pinned to the top of the CSDN homepage, and 300 people participated in replying to the discussion.
In addition to this application, this feature of appendChild can also be used in table sorting.
Note that the following table sorting code is only to illustrate the usage of appendChild and has not been tested in ff.
[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]
How about appendChild? With great help, this sorting is simple enough.
For more table operation methods and advanced custom table sorting, please refer to my other post on CSDN (the sorting is also implemented using appendChild and is compatible with firefox)
<script> function f(){ document.body.appendChild(document.getElementById("btn1")) } </script><script> // by Go_Rush(阿舜) from http://ashun.cnblogs.com/ var t=setInterval(myfunc,1000) function myfunc(){ d.appendChild(d.firstChild)} d.onmouseover=function(){clearInterval(t)} d.onmouseout=function(){t=setInterval(myfunc,1000)} </script><script> // by Go_Rush(阿舜) from http://ashun.cnblogs.com/ function $A(arrayLike){ for(var i=0,ret=[];i<arrayLike.length;i++) ret.push(arrayLike[i]); return ret } Array.prototype.each=function(f){for(var i=0;i<this.length;i++) f(this[i],i,this)} window.onload=function(){ $A(document.getElementById("tbl").rows).sort(function(tr1,tr2){ return Number(tr1.cells[0].innerHTML)>Number(tr2.cells[0].innerHTML)?1:-1 }).each(function(tr){ document.getElementById("tbl").firstChild.appendChild(tr) }) } </script>
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Replace String Characters in JavaScript

Custom Google Search API Setup Tutorial

8 Stunning jQuery Page Layout Plugins

Improve Your jQuery Knowledge with the Source Viewer

10 Mobile Cheat Sheets for Mobile Development
