Introduction:
Here I will explain how to add span tag to anchor or href or hyperlink using jQuery or jQuery add span tag inside of hyperlink or href.
Here I will explain how to add span tag to anchor or href or hyperlink using jQuery or jQuery add span tag inside of hyperlink or href.
Description:
In previous articles
I explained jQuery set maxlength for multiline textbox, jQuery stop form being submit on keypress, jQuery check undefined or empty value and many articles
relating to jQuery, JavaScript,
Asp.net,
SQL
server. Now I will explain how to add span tag in href using jQuery.
To
add span tag inside of hyperlink or href we need use prepend property in jQuery
for that we need to write the code like as shown below
<html>
<head>
<title>Add span tag inside of
href</title>
<script type="text/javascript"
src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(function () {
$('#btnAdd').click(function () {
$('#htitle').text('');
$('#htitle').prepend(" <span class=spntestclas>Hello </span>
there, friend");
})
})
</script>
<style type="text/css">
.spntestclas {
background: yellow;
font-weight:bold;
}
</style>
</head>
<body>
<input type="button"
id="btnAdd"
value="Add Span
Tag" />
<a href="#"
id="htitle"></a>
</body>
</html>
|
Once we run above query we will get output like as
shown below
Live Demo
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
4 comments :
You are very helpful. Jquery is best library in js. Thx
great!!!!!!!
Nice Post....
excellent
Note: Only a member of this blog may post a comment.