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

  • SEARCH
  • Home
  • 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 8013299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:36:01+00:00 2026-06-04T19:36:01+00:00

I am trying to set click handler for an anchor tag in jQuery mobile

  • 0

I am trying to set click handler for an anchor tag in jQuery mobile with via reference to the handler function inside the anchor tag (I need to do it this way for reasons that are cumbersome to get into). As illustrated in the code below when I pass a variable to the handler function that is an integer it works but when I pass it a string it does not. Can anyone explain whey this is?

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.css"
    />
    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.1.0-rc.1/jquery.mobile-1.1.0-rc.1.min.js"></script>
</head>

<body>
    <script>
        $(document).ready(function () {

            //The Line Below works
            $("#main").html('<a href="#" data-theme="a" onclick="test(' + '2' + '); return false" rel="external" data-role="button">click test</a>');

            /*
//The Lines Below Do not work
//$("#main").html('<a href="#" data-theme="a" onclick="test('+'hello world'+'); return false" rel="external" data-role="button">click test</a>');
var test = 'hello world';
//$("#main").html('<a href="#" data-theme="a" onclick="test('+test+'); return false" rel="external" data-role="button">click test</a>');
*/

            $("#main").trigger('create')

        });

        function test(e) {
            alert(e);
        }
    </script>
    <div data-role="page" class="type-interior">
        <div id="main" data-role="content"></div>
    </div>
</body>

  • 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-04T19:36:02+00:00Added an answer on June 4, 2026 at 7:36 pm

    try this ::

    var testParam = "'hello world'";
    
    $("#main").html('<a href="#" data-theme="a" onclick="test('+testParam +'); return false;" rel="external" data-role="button">click test</a>');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use a click handler. My function is as so (these are
I am trying to set the click event of a button on my form
I'm essentially trying to set it up so that when I click a button
I need help trying set-up Foreign Keys after having difficulty following Music library MySQL
Trying to figure out how to use EventToCommand to set a datagrid double click
I´m trying to use the JQuery UI Autocomplete plugin ( click to see the
I'm trying to set and onclicklistener so that when I click within the edittext
I am jQuery newbie and I have been trying to set up a file
I'm trying to set up some basic jQuery validation, but nothing seems to be
Im trying set the single table inheritance model type in a form. So i

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.