Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

jQuery Add Span Tag to Anchor or inside Hyperlink or href

Jan 2, 2014
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.
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.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

4 comments :

Ankastre said...

You are very helpful. Jquery is best library in js. Thx

Anonymous said...

great!!!!!!!

Anonymous said...

Nice Post....

Tariq hashmi said...

excellent

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.