Run script

Run script

Hi

I have this script that works fine in the console but won't when code is in the page html.

What do I write to get this to run when page is loaded. 

Maybe I am missing some document ready/function ready or such? 

The script is to send a query string to the next page if a person clicks a <a> tag.

Thanks in advance / Daniel

<script>
$('a').attr('href', function (index, value) {
  return value + window.location.search;
});
</script>