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.
答案 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/