如何设置<a> tag in <kbd> by javascript?

时间:2016-06-01 03:14:37

标签: javascript jquery html

I have a gsp with html code as below

<div class="custom-indicators-row-one">
    <div class="indicator-1 pull-left" >
        <kbd></kbd>
    </div>

How can I use JavaScript to set <a> inside <kbd> so I can define a url in it?

I had done it like this in JavaScript

$element.html(indic.link(url));

where $element is referring to <kbd>, indic is a value and url is to be opened when the value clicked. I noticed by this method I have the url open in new tab or can't change the color of the font.

1 个答案:

答案 0 :(得分:1)

您可以使用它在<a>

中设置<kbd>标记
var kbd = document.getElementsByTagName('kbd')[0];
kbd.innerHTML = '<a href="www.example.com" target="_blank">Click me</a>';

JSFiddle:https://jsfiddle.net/5caps8f3/