0

I want to display the header column text of a table(present within anchor) and bind alert event to anchor. I have tried something but it's not working

   <table style="width:20%;border:1;border-style:solid"   >
        <tr>
            <td>
               <a href="#">Header 1</a> </td>
            <td>
                <a href="#">Header 2</a></td>
            <td>
               <a href="#">Header 3</a></td>
        </tr>
        <tr>
            <td>
                R1C1</td>
            <td>
                R1C2</td>
            <td>
                R1C3</td>
        </tr>
        <tr>
            <td>
                R2C1</td>
            <td>
                R2C2</td>
            <td>
                R2C3</td>
        </tr>
    </table>

Please find the jquery used

  <script type="text/javascript">

        $(document).ready(function () {
            //should display Header 1, Header 2, Header 3
            $("table tr td a").each(alert($(this).text()));
            //Add click event for anchor
            $("table tr td a").click(function (e) { alert(); })
        });

    </script>

1 Answer 1

1
    $(document).ready(function () {
        //should display Header 1, Heder 2, Header 3
        $("table tr td a").each(function() {// need a function here
            alert($(this).text())
         });
        //Add click event for anchor
        $("table tr td a").click(function (e) { alert($(this).text()); return false;})
    });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.