Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get HTML button value to pass as a parameter to my javascript?

I have multiple buttons corresponding to multiple text areas to clear. I need to send to have a function to handle all of these buttons and handle each seperately

    <html>
    <head>
    <script src="jquery-1.6.js"></script>
    <script type="text/javascript">

        function getUniqueButtonValue(value)
        {
            alert(value);
            $("value").hide();
        }

    </script>
    </head>
    <body>

         <button id=someUinqueId value=something>Clear Selection</button>
    </body>
    </html>
like image 900
stackoverflow Avatar asked Dec 12 '22 10:12

stackoverflow


1 Answers

Setting aside the fact that you're placing a unique id in the value attribute rather than the id attribute... here's a fiddle.

$(document).ready(function(){
    $("button").click(function(){
        var me = $(this);
        // do whatever with me
        alert(me.val());
        me.hide();
    }); 
});
like image 112
canon Avatar answered Jan 17 '23 05:01

canon