Introduction:
Here I will explain how to disable hyperlinks using jQuery
or Enable / disable hyperlinks using jQuery.
Description:
In previous articles I explained jQuery Hover dropdown menu with css, jQuery show modal popup window on pageload, jQuery open videos in modal popup window, jQuery Draggable & Resizable div with example and many
articles relating to JQuery,
JavaScript, asp.net,
code snippets. Now I will explain how to disable hyperlinks
using jQuery.
Disable
hyperlinks in div
To disable particular link or particular div block of
hyperlinks we need to write the code like as shown below
$('#lnkhome').click(function(e) {
e.preventDefault();
});
// Disable Particular div block
hyperlinks
$('#linksdiv a').click(function(e) {
e.preventDefault();
});
|
If you want to see it in
complete example check below code
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Disable Hyperlinks using jQuery</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function()
{
// Disable Particular Hyperlink
$('#lnkhome').click(function(e) {
e.preventDefault();
});
// Disable Particular div block
hyperlinks
$('#linksdiv a').click(function(e) {
e.preventDefault();
});
})
</script>
</head>
<body>
<b>Disable Particular Link</b><br />
<a href='http://www.google.com' id="lnkhome">Google</a><br />
<b>Disable Particular DIV Block Links</b><br />
<div id="linksdiv">
<a href='http://www.facebook.com' id="lnkfacebook">facebook</a>
<a href='http://www.gmail.com' id="lnkgmail">gmail</a>
<a href='http://www.aspdotnet-suresh.com' id="lnkaspdotnet">Aspdotnet-Suresh</a>
<a href='http://www.yahoo.com' id="lnkyahoo">yahoo</a>
</div>
</body>
</html
|
Live
Demo
For live demo click on below links and see whether
those links redirect to another page or not
Disable Particular Link Disable Particular DIV Block Links |
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. |
|||
|
|||
3 comments :
nyc
please some one expalin function(e) what e contains i am new to jquery
but with new tab.., open de url
Note: Only a member of this blog may post a comment.