I want to use a hyperlink string in HTML page which I want to declare source link (URL) in my js file. Please tell me how can I call that URL from my js into html.
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are a number of different ways to do this. You could use document.createElement() to create a link element, and then inject the element into the DOM. Or you could use the
.innerHTMLproperty of an element that you already have on the page to insert the link using text. Or you could modify the “href” attribute of an existing link on the page. All of these are possibilities. Here is one example:Creating/Inserting DOM Nodes with DOM Methods
Assuming you have something like this in your HTML:
Creating/Inserting DOM Content with innerHTML
And another example using
innerHTML(which you should generally avoid using for security reasons, but which is valid to use in cases where you completely control the HTML being injected):Updating the Attributes of a Named DOM Node
Lastly, there is the method that merely updates the href attribute of an existing link:
… this assumes you have something like the following in your HTML: