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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:24:36+00:00 2026-05-25T00:24:36+00:00

I built a jquery plugin to which I’m passing the ID of an HTML

  • 0

I built a jquery plugin to which I’m passing the ID of an HTML checkbox as a parameter:

$("div.plugin").pluginname({
      chckBoxID: "chk" + $(this).attr("id")
});

The plugin generates an image link

(function( $ ){ 

    $.fn.extend({   

        pluginname: function(options){

            var defaults = {
                chckBoxID: ""
            }
            var options = $.extend(defaults, options);
            var o = options;
            $("div#" + imageDiv).html("<a><img src='images/x.gif'></img></a>");
        }
    });
});

By default, the checkbox is not checked.

What I want to do is:

(1) When the user clicks/checks the checkbox, the image link should open a new browser window.

(2) When the user unchecks the checkbox, the image link should not open a new browser window.

Your help is appreciated.

An update to my code —

HTML Code looks like this

<div>
    <input type="checkbox" id="chk1" />
</div>
<div class="plugin" id="1"></div>

<a><img> is generated by the plugin

$(this).html("<a><img src='images/x.gif'></img></a>");
  • 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-25T00:24:36+00:00Added an answer on May 25, 2026 at 12:24 am

    You can’t use $(this) the way you’re passing it into the plugin. You CAN do something like this though:

    $("div.plugin").each(function (i) {
        $(this).pluginname({
          chckBoxID: "chk" + $(this).attr("id")
        });
    });
    

    Then I believe what you’re trying to do in your plugin is something like this:

    (function ($) {
        $.fn.pluginname = function (options) {
            var opts = $.extend({}, $.fn.pluginname.defaults, options);
    
            var pluginnameClick = function (e) {
                if ($("#" + opts.chckBoxID).is(":checked")) {
                    e.preventDefault();
                    window.open($(this).attr('href'));
                }
            };
    
            $(this).each(function (i) {
                $('a', $(this)).bind("click", pluginnameClick);
            });
        };
    
        $.fn.pluginname.defaults = {
            chckBoxID: "chk"
        }
    })(jQuery);
    

    This assumes your HTML code looks something like this:

    <div class="plugin" id="1">
        <a href="link1.htm"><img src="image.jpg" /></a>
        <input type="checkbox" id="chk1" />
    </div>
    <div class="plugin" id="2">
        <a href="link2.htm"><img src="image.jpg" /></a>
        <input type="checkbox" id="chk2" />
    </div>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form which is built dynamically using this jQuery plugin http://code.google.com/p/jquery-dynamic-form/ When
I'm using a jQuery plugin which accepts a user parameter which can hold several
I have this jQuery plugin called Easy Slider which I'm implementing on this site
I am using the jQuery plugin from the jQuery build of TinyMCE. This simplified
I built a Jquery dropdown menu using this tutorial . It works across browsers
It seems like this should be something built into jQuery without the need for
I've built an mvc application which contains some jquery code. When I run the
I'm using the jQuery tablesorter plugin to sort a table, which assigns .click() handlers
I essentially have the same goal as in this question: Calling a jQuery plugin
We've built an AJAX website which uses JQuery UI extensively. we have 30+ homemade

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.