Home > Article > Web Front-end > How to get the value of href in a tag with jquery
Jquery method to get the value of href in a tag: first create a function in the js tag; then get the a tag object through the id in the function, and use the attr method to get the value of the href attribute; finally The obtained value can be output using the alert method.
The operating environment of this tutorial: Windows 10 system, jquery version 2.2.4. This method is suitable for all brands of computers.
(Learning video sharing: javascript video tutorial)
The specific steps are as follows:
Create a new html file , named test.html, is used to explain how jquery obtains the href value of the a tag.
In the test.html file, use the a tag to create a link and set its href attribute to "This is the link address".
In the test.html file, set the id of the a tag to myid, which is mainly used to obtain the a tag object through this id below.
In the test.html file, use the button tag to create a button with the button name "Get the href value of the a tag".
In the test.html file, bind the onclick event to the button button. When the button is clicked, execute the myfun() function.
In the js tag, create the myfun() function. Within the function, obtain the a tag object through id(myid), and use the attr() method to obtain the value of the href attribute. , and output the obtained value using the alert() method.
Open the test.html file in the browser, click the button to view the results.
For more programming-related knowledge, please visit: Programming Courses! !
The above is the detailed content of How to get the value of href in a tag with jquery. For more information, please follow other related articles on the PHP Chinese website!