p5.js | createA() Function
Last Updated :
26 Nov, 2021
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.
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.
javascript
var link;
function setup() {
createCanvas(400, 200);
background( 'green' );
"Go to GeeksforGeeks" , "_blank" );
link.position(120, 80);
}
|
Output:
After clicking the link, GeeksforGeeks home page will open in a new tab.
Reference: https://p5js.org/reference/#/p5/createA
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...