Memoc Memoc - 6 months ago 16
HTML Question

How to set <a> tag in <kbd> by javascript?

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.

Answer

You can use this to set <a> tag inside <kbd>

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

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