Switch to full style
JQuery Examples
Post a reply

change link <a> attributes dynamically

Mon Dec 31, 2012 1:23 pm

Change href , target ... etc dynamically or any HTML elements attributes using JQuery.
Code:
<html>
<
head>
<
title>Change HTML elements attributes using JQuery</title>

<!--
 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
 Note you can download the JQuery package instead of using Google version. --> 
<script src="jquery-1.8.3.js"></script>
<script>
$(document).ready(function(){
  $("button#L1").click(function(){
    $("#link").attr("href","http://www.codemiles.com");
  });
  
    $("button#L2").click(function(){
    $("#link").attr("target","_parent");
  });
});
</script>
</head>

<body>
<button id="L1">Change Href</button>
<button id="L2">Change Target</button>
<p><a href="#" id="link"  target="_blank" >Sample</a></p>

<p>Press on buttons to change link element attributes </p>
</body>
</html>




Post a reply
  Related Posts  to : change link <a> attributes dynamically
 Change the default underline style of link     -  
 Change the border color of image and its link     -  
 Change the link font family and weight     -  
 lesson3 :XSD Attributes     -  
 get HTML elements attributes values using JQuery     -  
 Dynamically Create Image     -  
 Add new row dynamically to table using JQuery     -  
 Calling Functions Dynamically     -  
 Uplading Files Dynamically Using SSIS     -  
 invoke class method dynamically in php     -  

Topic Tags

JQuery Content