NiallRedmond NiallRedmond - 1 month ago 8
HTML Question

HTML turn a link into a button

<a href="#">
<div class="col-md-4 promo-item item-1">
<h3>
Unleash
</h3>
</div>
</a>


I got a template online, the above (with css/bootstrap?), is an image that is a link. I want to change it so that instead of a link (
href
), it's a clickable button.

My plan is for the button to use JavaScript to change some of the content on the page, basing it off the JavaScript below;

<button type="button" onclick="document.getElementById('demo').innerHTML='Hello JavaScript!' ">
Click Me!
</button>


So how do I change this
href
into a button?

Answer

in bootstrap you just add the button classes and it will look like a button

<a class='btn btn-default' ...

However, there is no reason you can't just copy the onclick attribute to the anchor tag (or "href" as you keep calling it).


From your code in the comments:

<div id='demo'></div>

<a onclick="document.getElementById('demo').innerHTML='Hello JavaScript!'; return false; "> Click Me!&gt; <div class="col-md-4 promo-item item-1"> <h3> Unleash </h3> </div> </a>