JSFiddle - React, Tailwind, and code Playground

by Paulpro

HTML

<a href="process/purchase-weapon.php" target="_None">Buy!</a><br />
<a href="process/sell-weapon.php" target="_None">Sell!</a><br />
<a href="page/weapon.php?id=10" target="_Load-thediv">Info</a><br />
<div id="thediv">Weapon info will be loaded here.</div>

JavaScript

(function(){
    var as = document.getElementsByTagName('a');
    for(var i = 0; i < as.length; i++){
        if(as[i].getAttribute('target') == '_None')
            as[i].onclick = targetNone;
        if(as[i].getAttribute('target').substring(0, 5) == '_Load')
            as[i].onclick = loadIntoTarget;
     }
    
    function targetNone(){
        alert('Make Ajax call to "'+this.href+'"');
        return false;
    }
    
    function loadIntoTarget(){
        alert('Make Ajax call to "'+this.href+'", and put it in "'+this.getAttribute('target').substring(6)+'"');
        document.getElementById(this.getAttribute('target').substring(6)).innerHTML = 'Ajax Result';
        return false;
    }
})();