How do I add an attribute in an anchor tag? I want to make a module which will add some attributes in an anchor tag, whether the user adds in CKEditor or it is from Drupal menu system, before rendering it to the browser.

I can do it through jQuery with $('a').attr('data-anchor', 'arial');, but is there any way to do it through a module?
You can do it using hook_link_alter

/**
 * Implements hook_link_alter().
 */
function mymodule_link_alter(&amp;$variables) {

    $variables['options']['attributes'] = array('data-anchor' =&gt; 'arial');

}