How to Create a Website Link Dynamically using jQuery

In this tutorial we will create a How to Create a Website Link Dynamically using jQuery. This tutorial purpose is to teach how to create your own website link dynamically. This will cover all the important parts for creating html form for generating link. I will provide a sample program to show the actual coding of this tutorial.

This tutorial is easy to understand just follow my instruction I provided and you can do it without a problem. This program is useful if you want to put a website link for your website. I will try my best to give you the simplest way of creating this program How to Create a Website Link Dynamically. So let’s do the coding.

Before we get started:

First you have to download the jQuery plugin.

Here is the link for the jQuery that i used in this tutorial https://jquery.com/.

Lastly, this is the link for the template that i used for the layout design https://getbootstrap.com/.

Creating The Interface

This is where we will create a simple interface for our application. This code will display the html form for generating a url link. To create this simply copy and write it into your text editor, then save it as

<!DOCTYPE html>
<meta charset=“UTF-8” name=“viewport” content=“width=device-width, initial-scale=1”/>
<link rel=“stylesheet” type=“text/css” href=“css/bootstrap.css”/>
<nav class=“navbar navbar-default”>
<a class=“navbar-brand” href=“https://sourcecodester.com”>Sourcecodester</a>
<div class=“col-md-6 well”>
<h3 class=“text-primary”>How to Create a Website Link Dynamically</h3>
<hr style=“border-top:1px dotted #ccc;”/>
<input type=“text” placeholder=“Website name” id=“name” class=“form-control”/>
<input type=“text” placeholder=“URL” id=“url” class=“form-control”/>
<button type=“button” id=“create” class=“btn btn-success btn-block”><span class=“glyphicon glyphicon-link”></span> Create Link</button>
<div class=“col-md-6”>
<script src=“js/jquery-3.2.1.min.js”></script>
<script src=“script.js”></script>
</body>

Creating JavaScript Function

This is where the main function of the application is. This code will store the inputted data and will display it as a website link. To do this just copy and write these block of codes inside the text editor and save it as

$(document).ready(function(){
$(‘#create’).on(‘click’, function(){
$(‘#result’).append(“<a href='”+url+“‘ target=’_blank’>”+name+“</a><br />”);
$(‘#name’).val();
$(‘#url’).val();

In the given code we first call the basic jQuery ready event to signal that the DOM of the page is now ready to be use. After that we bind the button to trigger a certain functions using the on() function. We then create a variable that will hold the html data. To display our website link we just simply append the inputted html form data back to the page using the jQuery append() function.

Output:

The How to Create a Website Link Dynamically using jQuery source code that I provide can be download below. Please kindly click the download button.

There you have it we successfully created How to Create a Website Link Dynamically using jQuery. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for JavaScript Language

This content was originally published here.

Scroll to Top