Solved

use javscript to trigger onclick event on image in jQuery zoommap

Posted on 2010-11-23
15
1,016 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:
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
 

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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
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 …

747 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now