Use JS to get the href value of the <a> tag in the HTML document.

Source: Internet
Author: User

Because you often use the QR code information in a website, each time you need to manually open the site, slide to the corresponding place, click a link to open the picture, so you want to use a script to get this information. Just JS can be very convenient to manipulate the HTML DOM, so write a simple function to try hackers.

Open the Web page, open the Browser debugging tool, get the corresponding page information, found that the node can use the following function to obtain the value of the href.

JS = Document.getelementsbyclassname ("Hover-text") [4].getelementsbytagname (' a ') [0].getattribute (' href ')

The value returned by this function is the value of the href of the a tag, with the address such as "img/qr/xxx.png", but this value cannot be used directly, so we need another way. As follows:

JS = Document.getelementsbyclassname ("Hover-text") [4].getelementsbytagname (' a ') [0].href

The returned data is:

"Http://example.com/img/qr/xxx.png"

This is exactly what I want. If there is more depth, the update will continue.

Use JS to get the href value of the <a> tag in the HTML document.

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.