Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

use javscript to trigger onclick event on image in jQuery zoommap

Posted on 2010-11-23
15
Medium Priority
?
1,024 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
  • 10
  • 4
15 Comments
 
LVL 16

Accepted Solution

by:
Justin Mathews earned 2000 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
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!

 

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:Justin Mathews
Justin Mathews earned 2000 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:Justin Mathews
Justin Mathews earned 2000 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:Justin Mathews
Justin Mathews earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Find out what you should include to make the best professional email signature for your organization.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this tutorial viewers will learn how to style a decorative dropcap for the first letter in a paragraph using CSS. In CSS, create a new paragraph class by typing "p.fancy": Then, to style only the first letter of the first sentence, include the ps…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…
Suggested Courses

926 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