Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • how to bind click event on dynamically created elements

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 170
    Comment on it

    Below is the example for how to bind click event on dynamically created elements.
    If you having trouble with such issues, then use the below code.

    Here is the HTML

    <a href="#" class="button">Button</a>
        <div class="list-cover">
            <table>
                <thead>
                    <tr>
                        <th>first</th>
                        <th>Second</th>
                        <th>last</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td>first</td>
                        <td>Second</td>
                        <td>last</td>
                    </tr>
                    <tr>
                        <td>first</td>
                        <td>Second</td>
                        <td>last</td>
                    </tr>
                    <tr>
                        <td>first</td>
                        <td>Second</td>
                        <td>last</td>
                    </tr>
    
                    <tr>
    
                        <td>first</td>
                        <td>Second</td>
                        <td>last</td>
                    </tr>
                    <tr>
                        <td>first</td>
                        <td>Second</td>
                        <td>last</td>
                    </tr>
                </tbody>
            </table>
        </div>
    

    Here is the CSS

    table{
        width:100%;
    }
    
    table th{
        text-align:left;
    }
    
    .list-cover{
        width:500px;
        margin:auto;
    }
    

    Here is the Code(JQuery)

    $(function(){
        $('.button').click(function(){
            var html = $('.list-cover').html();
                 $(html).appendTo('.list-cover');
            $(html).prependTo('.list-cover');
        });     
    });
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: