The jQuery library provides various options
to work with href links, in this post Asp.Net jQuery loop
through all href controls in a Page, we
shall see on how to loop through all the Hyperlink controls in a page using jQuery.
We can loop through all the Hyperlink controls
in a page using jQuery as follows.
alert('Link: '
+ $(this).text());
});
Here is a full example
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Links
(a href)</title>
<link
type="text/css"
href="Stylesheet.css"
rel="Stylesheet" />
<script
type="text/javascript"
src="JavaScript/jquery-1.7.2.js"></script>
<script
type="text/javascript"
language="javascript">
$(document).ready(function()
{
$('#cmdLoop').click(function(event) {
event.preventDefault();
$('a').each(function() {
alert('Link: ' + $(this).text());
});
});
});
});
</script>
</head>
<body>
<form id="frmLinks" runat="server">
<b>Links (a
Href)</b><br
/>
<a id="lnkGoogle"
href="http://www.google.com"
target="_blank">Google</a>
<br />
<a id="lnkYahoo" href="http://www.yahoo.com">Yahoo</a><br
/>
<a id="lnkFacebook" href="http://www.facebook.com">Facebook</a><br
/>
<br /><br />
<b>Hyperlinks
(asp:HyperLink)</b><br />
<asp:HyperLink
ID="lnkMicrosoft"
runat="server"
Text="Microsoft"
NavigateUrl="http://www.microsoft.com/">
</asp:HyperLink><br />
<asp:HyperLink
ID="lnkMSDN"
runat="server"
Text="MSDN"
NavigateUrl="http://msdn.microsoft.com/en-US/">
</asp:HyperLink>
<br /><br />
<asp:Button
ID="cmdLoop"
runat="server"
Text="Loop"
Width="100"/>
</form>
</body>
</html>
Run the application, Click on the Loop button, notice that the details of all the Hyperlinks in the page appear in a Message box.
Run the application, Click on the Loop button, notice that the details of all the Hyperlinks in the page appear in a Message box.
Related Post
Asp.Net jQuery get href link
Asp.Net jQuery get href ID
Asp.Net jQuery get href target Attribute
Asp.Net jQuery get Link Text
Asp.Net jQuery set href URL
Asp.Net jQuery set href Text
Asp.Net jQuery set href Target Attribute
Asp.Net jQuery href click Event Handler
Asp.Net jQuery href mouse hover Event Handler
Asp.Net jQuery loop through all href controls in a Page
Asp.Net jQuery href Example
Asp.Net jQuery get href link
Asp.Net jQuery get href ID
Asp.Net jQuery get href target Attribute
Asp.Net jQuery get Link Text
Asp.Net jQuery set href URL
Asp.Net jQuery set href Text
Asp.Net jQuery set href Target Attribute
Asp.Net jQuery href click Event Handler
Asp.Net jQuery href mouse hover Event Handler
Asp.Net jQuery loop through all href controls in a Page
Asp.Net jQuery href Example
No comments:
Post a Comment