Home Javascript JavaScript method anchor()



JavaScript method anchor()
Posted on: April 3, 2006 at 12:00 AM
This section illustrates you the use of JavaScript anchor() method. The anchor() method creates an HTML anchor with a NAME attribute on the specified text.

JavaScript method anchor()

     

This section illustrates you the use of JavaScript anchor() method. The anchor() method creates an HTML anchor with a NAME attribute on the specified text.

 

 

 

 

Its syntax is:

[string_object].anchor("anchor_name")

The anchor_name argument passed into the method anchor() is placed in the "NAME" attribute of the html anchor. In the given example, we have created a function display() and called the anchor() method on a String object. We have created a button which calls the function display() from the script and creates an html anchor by adding an anchor to the string specified . 

Here is the code:

<html>
<script>
function display(){
var txt="Hello world!";
alert((txt.anchor("myanchor"));
}
</script>
<h2>Use of anchor() method</h2>
<button onclick="display();">
Use of Anchor method
</button>
</html>

Output will be displayed as:

On clicking the button, you will see that the HTML anchor is created. This is shown in the alert box.

Download Source Code:

 

     

Related Tags for JavaScript method anchor():


More Tutorials from this section

Ask Questions?    Discuss: JavaScript method anchor()  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.