Solved

use javscript to trigger onclick event on image in jQuery zoommap

Posted on 2010-11-23
15
1,021 Views
Last Modified: 2012-05-10
I am using http://www.gethifi.com/blog/a-jquery-plugin-for-zoomable-interactive-maps for an interactive map. I added a legend. One icon on the legend should trigger a clickable region on the map and thereby cause the map to zoom in. How can I create such an oncllick event to make the browser click that zoomable region? Will some CSS do or do I need JavaScript?
0
Comment
Question by:rhandalthor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 10
  • 4
15 Comments
 
LVL 16

Accepted Solution

by:
jmatix earned 500 total points
ID: 34198627
If the zoomable region has an ID 'zoomrgn', you can add this jQuery code:

$('#zoomrgn').click();

to invoke a click on that region.

0
 

Author Comment

by:rhandalthor
ID: 34198836
@ jmatix How would I add that code to divs - one for each legend icon or an image (legend image?
0
 

Author Comment

by:rhandalthor
ID: 34198889
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:rhandalthor
ID: 34198992
I guess I would have to load something like
$('#other').click(function() {
  $('#target').click();
});

Open in new window

0
 
LVL 16

Assisted Solution

by:jmatix
jmatix earned 500 total points
ID: 34199067
If all <img>s have a common class, say, legend i.e. <img class='legend'>

Then you can say:

$('.legend').click(function() {
  $('#target').click();
});

It will apply it for all images.
0
 

Author Comment

by:rhandalthor
ID: 34199156
Loaded
 $('#destinations-legend').click(function() {
  $('#kadavu').click();
});

Open in new window

Just to make the whole legend image a trigger. Reloaded the page. No luck yet and an error:
$ is not defined
http://abc.com
Line 1

Open in new window

0
 
LVL 16

Assisted Solution

by:jmatix
jmatix earned 500 total points
ID: 34199267
Have you included jquery.js at the top as:

<script src="http://code.jquery.com/jquery-latest.js"></script>

0
 

Author Comment

by:rhandalthor
ID: 34199386
WordPress normally loads jQuery on the home page and all pages unless blocked and it is loaded on that page. I checked using Firebug. Maybe the legend.js is loaded too late or too early to work with jQuery?
0
 

Author Comment

by:rhandalthor
ID: 34199500
Read http://wpengineer.com/2028/small-tips-using-wordpress-and-jquery/ and tried
]jQuery(function ($) {
// Now you can use $ as a reference to jQuery without any problem
$('#destinations-legend').click(function() {
$('#kadavu').click();
 });
}); 

Open in new window

in legend.js which I load using
wp_enqueue_script('legend', '/wp-content/themes/decondo-child/lib/scripts/legend.js');

Open in new window


No luck yet :-(
0
 
LVL 7

Expert Comment

by:dxdinh
ID: 34199806
do you url to page that I can take a look at the error messages?
0
 

Author Comment

by:rhandalthor
ID: 34199872
Site is not open to the public yet. I see this error:
$ is not defined
http://abc.com
Line 1

Open in new window


when I use this
$('#destinations-legend').click(function() {
$('#kadavu').click();
}); 

Open in new window

When I check other script loaded i DO see jQuery JavaScript Library v1.4.2 . legend.js is loaded before jQuery in the header.
in legend.js
0
 
LVL 16

Assisted Solution

by:jmatix
jmatix earned 500 total points
ID: 34199897
Can you move loading of legend.js down to be below jquery.js so that it loads after jquery.js?
0
 

Author Comment

by:rhandalthor
ID: 34199942
Trying to figure out how to do that with the WordPress'
wp_enqueue_script('legend', '/wp-content/themes/decondo-child/lib/scripts/legend.js');

Open in new window

in function.php. Never done that before..
0
 

Author Comment

by:rhandalthor
ID: 34200117
wp_enqueue_script('legend', '/wp-content/themes/decondo-child/lib/scripts/legend.js','jquery');

Open in new window


was supposed to load the script and make it clear to WordPress that it depends on jQuery, but I still get
jQuery is not defined
http:/abc.coms?ver=3.0.1
Line 1

Open in new window

using
jQuery(document).ready(function ($) {
$('#destinations-legend').click(function() {
$('#kadavu').click();
});
});

Open in new window

0
 

Author Comment

by:rhandalthor
ID: 34200168
OK. Working. Had to load it before wp_head() in the parent theme :-)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question