2

I want to apply all the events of "one" to => "two". Events are dynamic with some dynamic ID. Some data is coming on click on one. want to achieve same on click of two (get all events from one)

<div class="one">One</div>

<div class="two">two</div>

want to achieve something like this:- Copy events from one element to other using jquery

but didn't understood it fully. So I made very simple example and wanted to achieve that.

Can we achieve this with Jquery or Javascript?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Yogesh
  • 331
  • 1
  • 4
  • 10

1 Answers1

1

$('.one,.two').click(function(){
  alert("One");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
<div class="one">One</div>

<div class="two">two</div>

use $('.one,.two') selector to combine both div

or

give same class to all divs

    $('.one').click(function(){
      alert("One");
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script>
    <div class="one">One</div>

    <div class="one">two</div>

or

Call the event manually using trigger

$('.one').trigger('click');.

Sumesh TG
  • 2,557
  • 2
  • 15
  • 29
  • Thanks Sumesh it helped to some extent. But found that I wanted it differently. Updated the question again – Yogesh Oct 26 '18 at 09:47
  • 1
    I couldn't understand your requirement completely. You can fire an event programmically like this `$('.one').trigger('click');`. – Sumesh TG Oct 26 '18 at 09:59