javascript - Add pre link to all links in a div, On link click execute function -


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  <script> $.getjson('http://anyorigin.com/get?url=microsoftwebpro.com&callback=?', function(data){   $('#output').html(data.contents); }); </script>  <div id="output"></div> 

i have following code, , i'm trying prepend link http://anyorigin.com/get?url=thislinkisinhtml.com&callback=? every link. next thing on link click call above script , have change div "output". runs on 1 page in div , won't affected link clicks.

the code below edit links on page.

$('a').each(function() {     $(this).attr('href', 'http://anyorigin.com/get?url='+$(this).attr('href')+'&callback=?'); }); 

the code below called on every link click.

$('a').click(function() {     $.getjson($(this).attr('href'), function(data) {         $('#output').html(data.contents);     }); }); 

Comments