Laravel onclick function not working

There could be any reason that laravel onclick function not working in your case. Here we provide code snippet on onclick event which helps you to find out the solution for your problem

Answers 2
  • Get data-id attribute value using onclick event on button in javascript

    <button data-id="5" onclick="followUser(this); return false;">Follow</button>
    
    <script>
    function followUser(e){
        var id = e.getAttribute('data-id');
        console.log(id);
    }
    </script>
    
    0

    This code snippet will help you to get the value of data-id attribute using onclick event on button in javascript.

  • JQuery get data id attribute value on click button

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <button type="button" data-id="5" id="Button">Follow</button>
    <script>
    $(document).ready(function(){
        $('#Button').on('click', function(){
        	var value = $(this).attr('data-id');
            alert(value);
            console.log(value);
        });
    });
    </script>
    
    0
  • Back to code snippet queries related laravel