Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8745127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:57:20+00:00 2026-06-13T11:57:20+00:00

I want to pass parameter when I click in <a href> , first I

  • 0

I want to pass parameter when I click in <a href>, first I have this and works fine:

    <a href="#" rel="like{{num}}"> I like </a>|

   $("a[rel^='like']").click(function(){
            $.ajax({
                ...
            });

but I don’t know how to pass parameter to that function, so I do this:

    <a href="#" rel="like{{num}}"
          onclick="cap(para1, para2)"> I like </a>

Finally, in my Javascript I have this simple function:

    function cap(para1, para2){
        alert('here');
    }

but I obtain this error:

ReferenceError: cap is not defined

Any idea?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:57:21+00:00Added an answer on June 13, 2026 at 11:57 am

    A solution is to use data attributes :

    <a href="#" rel="like{{num}}" data-para1="Oh"  data-para2="{{somepara}}"> I like </a>
    
    <script>
    function cap(para1, para2){
        alert('here');
    }
    $("a[rel^='like']").click(function(){
       var para1 = this.dataset['para1'];
       var para2 = this.dataset['para2'];
       cap(para1, para2);
    });
    </script>
    

    You may also write it like this if you prefer a more structured approach :

    <a href="#" rel="like{{num}}" data-params="{'para1':'Oh','para2':'{{somepara}}'}"> I like </a>
    
    $("a[rel^='like']").click(function(){
       var params = this.dataset['params'];
       var para1 = params.para1;
       var para2 = params.para2;
    

    Note that if the document isn’t an HTML5 document you’ll have to use the more compatible data function of jQuery (but there hardly is any reason not to use HTML5 doctype today) :

    var para1 = this.data('para1');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have this jquery function that i want to pass topic parameter to, i
I have a function that i want to pass as a parameter function myFun(){
I have this class which I want to pass around Windows as LPARAM parameter.
I want to pass buttonClick method as a parameter to the function: we have
I have two functions click and live. I want to pass a parameter from
I have this link: <a id='delete' href='/add/delete.php?iid=XXXXX'>#</a> And I want to pass it on
I have following code and i want to pass additional parameter in JSON.getJSONfromURL() method
I have a NameValueCollection with parameter. I want to pass all parameter in SqlCommand
I would like to pass parameter from view to controller in cshtml page. This
I have a wpf button like this: <Button Click=button1_Click Height=23 Margin=0,0,5,0 Name=button1 Width=75>Initiate</Button> And

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.