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 342999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:51:24+00:00 2026-05-12T10:51:24+00:00

I am trying to pass one variable to a jQuery function inline (i.e.: using

  • 0

I am trying to pass one variable to a jQuery function inline (i.e.: using an onMouseOver="function();" within the actual link (which is an area tag from an image map)).

The function is only being called if I place it before the $(document).ready(function(){ line, but doing this is causing all sorts of problems with jQuery.

All I want is for a simple tag (such as <area shape="circle" coords="357,138,17" onMouseOver="change('5');" id="5" /> to launch a function that is contained within the normal jQuery body of code.

To illustrate the point, the following works:

<script type="text/javascript">
function myfunction(x)    {  alert(x); //Alerts 2  
}
</script>

<img src="/shared_images/loading.gif" border="0" usemap="#Map">
<map name="Map"><area shape="rect" coords="171,115,516,227"
onMouseOver="myfunction('2')"></map>

But the following doesn’t

<script type="text/javascript" src="scripts/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function myfunction(x)    {  alert(x); //Nothing happens   
}
}
</script>

<img src="/shared_images/loading.gif" border="0" usemap="#Map">
<map name="Map"><area shape="rect" coords="171,115,516,227"
onMouseOver="myfunction('2')"></map>
  • 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-05-12T10:51:24+00:00Added an answer on May 12, 2026 at 10:51 am

    In your second example, you’ve declared myfunction inside the anonymous function you’re passing to .ready(). That means myfunction is a local variable, which is only in scope inside that anonymous function, and you cannot call it from anywhere else.

    There are two solutions.

    First, you can declare it outside (before or after) the call to .ready(). This should not cause any interference with jQuery. If it does, something else is wrong (perhaps a simple syntax error?) that we’d welcome you to bring up in a StackOverflow question.

    Second, you shouldn’t be using onMouseOver="" to attach event handlers (as that mixes JavaScript with HTML), so let’s do away with it entirely. Replace your JavaScript with this:

    $(document).ready(function() {
        $("#that-area-down-there").mouseover(function() {
            alert(2);
        });
    });
    

    And your HTML with this:

    <area shape="rect" coords="171,115,516,227" id="that-area-down-there" />
    

    (Presumably you’ll want to replace that id with something more meaningful in context, of course.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 204k
  • Answers 204k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If you use NSOperations you can use the addDependency: method… May 12, 2026 at 8:51 pm
  • Editorial Team
    Editorial Team added an answer If you need exact decimal values, you should use java.math.BigDecimal.… May 12, 2026 at 8:51 pm
  • Editorial Team
    Editorial Team added an answer If your goal is to take any text input and… May 12, 2026 at 8:51 pm

Related Questions

I am trying to customise fancybox so that when one of the 4 images
I am trying to write a regular expression to match and split a custom
I am trying to create a report in SSRS2000 that will query an ORACLE
Consider this simple xml element example: <parent foo=1 bar=2 foobar=3> <child/> </parent> In the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.