Javascript nextsibling encounters space problems

Source: Internet
Author: User

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:

  1. VaR objlink = Document. getelementbyid ("Link ")
  2. VaR objnext = ojblink. nextsibling
  3. For (P in objnext)
  4. {
  5. Alert (p + "=" + objnext [p])
  6. }
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.