Replace Text with link click.

Replace the text in a div with the rel attribute in an a tag.

by Nirvanachain

HTML

<div id="myDiv">
  <div>Hello World</div>  
  <p>
    <a href="#" class="myLink" rel="123">Link 1</a>
  </p>    
  <p>    
    <a href="#" class="myLink" rel="abc">Link 2</a>
  </p>
    
</div>

JavaScript

$("#myDiv p .myLink").each(function(index, domEle) {
    $(this).bind('click', function(){
      var x = $(this).attr('rel');
        $('#myDiv div').html(x);
    });
});