Hướng dẫn set href javascript
An Show Nội dung chính
If you want it to render correctly as a link (ie underlined, hand pointer, etc), then it will only do so if it has a Code like this is therefore sometimes used as a way of making a link, but without having to provide an actual URL in the He probably has some javascript event code elsewhere which is triggered when the link is clicked, and that will be what he wants to actually happen, but he wants it to look like a normal Some developers use There are ways around these things. Using an empty bit of Javascript code in the ❮ HTML tag ExampleThe href attribute specifies the link's destination: Try it Yourself » More "Try it Yourself" examples below. Definition and UsageThe If the Tip: You can use Browser Support
SyntaxAttribute Values
More ExamplesExampleHow to use an image as a link: Try it Yourself » ExampleHow to link to an email address: Try it Yourself » ExampleHow to link to a phone number: Try it Yourself » ExampleHow to link to another section on the same page: Try it Yourself » ExampleHow to link to a JavaScript: Try it Yourself » ❮ HTML tag ❮ Anchor Object ExampleChange the destination (URL) of a link: document.getElementById("myAnchor").href = "http://www.cnn.com/"; Try it Yourself » Definition and UsageThe href property sets or returns the value of the href attribute of a link. The href attribute specifies the destination of a link. Browser Support
SyntaxReturn the href property: Set the href property: Property Values
Technical Details
More ExamplesExampleGet the URL of a link: var x = document.getElementById("myAnchor").href; Try it Yourself » ExampleAnother example of how to get the URL of a link (a relative URL): var x = document.getElementById("myAnchor").href; Try it Yourself » Related PagesHTML reference: HTML href attribute ❮ Anchor Object |