p5.js | createA() Function

The createA() function in p5.js is used to create an anchor element in the DOM (Document Object Model) for creating a hyperlink. This function includes the p5.dom library. Add the following syntax in the head section.

filter_none

edit
close

play_arrow

link
brightness_4
code

chevron_right


Syntax:

createA( href, html, target )

Parameters:

  • href: It holds the url of the page to the link.
  • html: It holds the display text.
  • target: It holds the target where the link will open.

The “target” can be ‘_blank’ (link will open in a new tab), ‘_self’ (link will open in the same tab), etc.

Example: This example uses createA() function to create a link of GeeksforGeeks home page.

filter_none

edit
close

play_arrow

link
brightness_4
code

// Create a variable for anchor object
var link;
   
function setup() {
      
    // Create a canvas
    createCanvas(400, 200);
      
    // Set the background-color
    background('green');
      
    // Create a anchor object using createA() function
    link = createA("https://www.geeksforgeeks.org/",
                       "Go to GeeksforGeeks", "_blank");
      
    // Posotion the anchor objects
    link.position(120, 80);    
}

chevron_right


Output:

After clicking the link, GeeksforGeeks home page will open in a new tab.

Reference: https://p5js.org/reference/#/p5/createA



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.