简体   繁体   中英

Jquery how to trigger click on an element that gains focus

I am working with caph framework and i trying to click in every id focused

$(event.currentTarget).on('selected',function() {

    var value = $(this).prop('id');

    $('#' + $(this).prop('id')).trigger('click');

});

You can access the event target with $(this) in jQuery. To automatically click on the selected element you could do

$(event.currentTarget).on('select', function() {
     $(this).click()
     // or $(this).trigger('click')
};

If I understand your question right though you're asking how to click every element with a given ID - please note that you should be using classes for this, as IDs are supposed to be unique. You could achieve that with the following:

$(event.currentTarget).on('select', function() {
     $('.yourClassName').click()
};

This will click on every element with the given class.

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