Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a javascript Function from href tag in html?

How to call a JavaScript Function from href tag in html? I have created few tabs . I want when user clicks on any tab the href along with JavaScript function should get called. How can I do it?

<?php if($order == 1){ ?>
<li class="cat-one"><a href= "javascript:loadProducts($categoryId)" > <?php echo $categoryName ?> </a></li>
<?php } ?>

This is my Javascript

<script type="javascript" >
function loadProducts($categoryId)
{
    alert("Hello World!");
    return false;
}

</script>
like image 278
ScoRpion Avatar asked Nov 16 '11 09:11

ScoRpion


1 Answers

In the href tag, without specifying a link, specify your javascript function name.

For example

<a href='javascript:myFunction()'> Click Me! <a/>
like image 62
Ranhiru Jude Cooray Avatar answered Sep 17 '22 23:09

Ranhiru Jude Cooray