Other option to trigger javascript function

I have the following javascript function which works nicely on a single html file.

jQuery.noConflict();
jQuery(function() {
    $('#focus-init').click(function() {
        $('#map1').vectorMap('set', 'focus', 1, 0, 0);
    });
});

The issue appears when I try to integrate the above function into my wordpress theme. It seems that any other page I browse the above function is always called which I don't expect it to happen.

Since the #focus-init only exist on one page how can I specify that the above function should only be called when the element ID is found ?

UPDATE

I am afraid this wordpress theme does not have a concept of page title, since any other page has the same title tag

Answers


jQuery(function() {
    if ($('#focus-init').length !== 0) {
        $('#focus-init').click(function() {
            $('#map1').vectorMap('set', 'focus', 1, 0, 0);
        });
    }
});

Need Your Help

My application launchs twice on Honeycomb

android android-3.0-honeycomb launch dalvik

When I execute my application on Honeycomb it gets launched twice..

Destroy all controller action in rails

ruby-on-rails controller

I have a Notification model. All in all, this model is unimportant and is just to notify the user. I have no reason to keep this data.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.