简体   繁体   中英

Unable to call .click function - Jquery

I'm creating a Firefox/Chrome Addon that goes on a 3rd party website. On this site, there is a list of about 512 names in one ul . I want to put 12 of them, based on their values and compared to an array.

Each li item looks like so:

<li><a class="manip" href="javascript:void(0);"></a><span class="draggable in-MultiCheckPossibleUserIdslistpair-possible ui-draggable"><a class="user" href="javascript:jQuery.wp.showModalWindow('/OneProof/User/Info/31654022')">Aaron Quinby</a><span class="id">31654022</span><span class="sortNo">1</span></span><span class="preview" style="display: none;">Aaron Quinby</span></li>

Right now, clicking on the a tag, with manip class will bring the li item from one ul to the correct ul . I want to do this automatically with my addon. I figured the quickest way would be to call the .click() event with jQuery on the a tag like so:

$(document).ready(function() {
$(".manip").each(function() {
    //quick check to see if it works, click all
    $(this).click();
});
});

I've played with the click, calling it in the console, calling it after a delay, and few other ways.

The only JavaScript I can find associated with the manip class in the source for this site is the following:

universe.find("a.manip")
        .click(function() {
            //alert("bound");
            $.dropIt($(this).parent(), false);
        });

Is there a reason why the .click call event isn't working?

Thanks!

Edit: Universe is defined here:

function listpairCore(options) {
    var options = $.extend({}, $.fn.listPair.options, options);
    var thisId = this.attr("id");
    var ulSelected = this.find("ul.selected");
    var ulPossible = this.find("ul.possible");
    var universe = this;

and listpaircore is called here

$.fn.listPair = listpairCore;

The click function does not simulate a click. It binds an event handler to the click event.

What you want is

$(this).trigger( "click" );

Update:

The javascript you found in the source references the "manip" class as

universe.find("a.manip")

so maybe try doing the same?

$(document).ready(function() {
    universe.find("a.manip").each(function() {
        //quick check to see if it works, click all
        $(this).trigger("click");
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM