Question

Sample code:

<div id="first">first div</div>
<div id="second">second div, click here or on the previous it's the same</div>

Suppose I set an event onclick on the first div that alerts the div's content. How do I call that event? In example clicking on the second div I'd like it to call the click event of the first div and alert('first div')

Was it helpful?

Solution

Check out their Element.fireEvent() method. Try this:

$('first').addEvent('click', function()  { 
             alert($('first').innerHTML); 
});

$('second').addEvent('click', function()  { 
             $('first').fireEvent('click'); 
       });

OTHER TIPS

$('first').click();

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top