We can insert new element in to the DOM using appentTo() method. To perform dynamic html generation of anchor tag coupled with .attr() and appentTo() method. The following example shows you how to create dynamic html element in jQuery.
Example:
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<style type="text/css">
.titleText {
color: #0094ff;
font-family: arial;
}
</style>
<script>
$(function () {
$("<a>learn .net skillsfrom infinetsoft.com</a>")
.appendTo("#divResult")
.attr("class", "titleText")
.attr("href","http://www.infinetsoft.com")
.attr("title","infinetsoft");
});
</script>
</head>
<body style="width: 400px;height:250px; border: 1px solid #e5dddd;color:#f5a307;">
<h2>dynamicallygenerating html element </h2>
<div id="divResult" style="color:#0094ff;" >
</div>
</body>
</html>
Output:
Post your comments / questions
Recent Article
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
Related Article