Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Dev0ps's avatar

how to pass href value to jquery using onclick

code which works

            <a id="data" href="?blogId={{$obj->id}}&userId={{Auth::User()->id}}" class="post-add-icon inline-items">

But i want to hide link shown in the status bar in the lower side of the browser on hover

            <a id="data" href="javascript:void(0)" onclick="return '?blogId={{$obj->id}}&userId={{Auth::User()->id}}';" class="post-add-icon inline-items">

ajax code

  $(document).on('click','#LikeArticle',function(e) {
        e.preventDefault();
        var data = $(this).attr('href');
        NProgress.start();
        $.ajax({
            method: 'get',
            url: '/LikeArticle',
            data: data,
            async: true,
            cache: false,
            success: function (data){
                console.log(data);
              
                $('.LikeACountMemory-' + data.html.data.blog_id).html(data.html.view);
            }
        });
        NProgress.done();
        e.preventDefault();
        e.stopPropagation();
    });
0 likes
1 reply
lostdreamer_nl's avatar

put it in a data attribute and use jQuery's .data() method to get it out:

<a id="data" href="#" data-href="?blogId={{$obj->id}}&userId={{Auth::User()->id}}" class="post-add-icon inline-items">

Script

  $(document).on('click','#data',function(e) {
        e.preventDefault();
        e.stopPropagation();

        var data = $(this).data('href');
        NProgress.start();
        $.ajax({
            method: 'get',
            url: '/LikeArticle',
            data: data,
            async: true,
            cache: false,
            success: function (data){
                console.log(data);
              
                $('.LikeACountMemory-' + data.html.data.blog_id).html(data.html.view);
            }
        });
        NProgress.done();
    });

Please or to participate in this conversation.