Someone asked me how to use JavaScript to remove the following code:
<A href = "http://blog.csdn.net/sallay" id = "Link"> <br/> <Div id = "Div"> This is a div </div>
My answer is:
Document. getelementbyid ("Link"). removenode (true)
Document. getelementbyid ("Div"). removenode (true)
However, I ignored the intermediate <br/> and changed it:
Document. getelementbyid ("Link"). removenode (true)
Document. getelementbyid ("Link"). nextsibling. removenode (true)
Document. getelementbyid ("Div"). removenode (true)
However, during the experiment, I found that I ignored a problem, that is, there is a space between </a> and <br/>, so document. getelementbyid ("Link "). nextsibling. removenode (true) does not get the <br/> element, but the space.
At the same time, we can traverse all the attributes and values:
- VaR objlink = Document. getelementbyid ("Link ")
- VaR objnext = ojblink. nextsibling
- For (P in objnext)
- {
- Alert (p + "=" + objnext [p])
- }