html anchor tag's onclick was not working

ajax, html, javascript, jquery

Solution

It's because of conflicting `'` and a funciton definition instead of call (thanks @user1389596):

<a href='#' onclick="alert('hiii')">

that should work. The extra `'`s inside of the onclick made the browser view it as the end of the onclick attribute, which isn't what you want. This way, using two different types of quotes, it works fine.

Or, even better, don't use inline handlers:

<a href='#' id="thethingy">
<!--in a galaxy far, far away:-->
<script type="text/javascript">
    document.addEventListener('DOMContentLoaded',function(){
        document.getElementById('thethingy').addEventListener('click',function(){
            alert('hiii');
        },false);
    },false);
</script>

Problem

I was generating a table dynamically. Inside the td data , there is a hyperlink.inturn it should call a function. why the below code snippet was not working. Nothing happening when i click on the link. ``` <a href='#' onclick='function(){alert('hiii');}'> ```

Original source