2

Is it possible to trigger another onclick event upon clicking on a button?

i.e.

onclick="document.getElementById('link').onclick()"

I'm trying to get this working in ie6.

Tried the jquery script but no luck in ie6:

<textarea style="height:80px; border:0px;" name="box3" id="box3" cols="58" rows="7" class="title">FUTURE: </textarea> 
<script> $('#box3').click(function() { $('#link').click(); }); </script> 
<a id="link"><div id="test3-header" class="accordion_headings future" >FUTURE</div></a>

1 Answer 1

5

Yes. It's easiest using jQuery:

$('#buttonActuallyClicked').click(function() {
    $('#buttonBeingFakeClicked').click();
});

This will "fake" a click on the element with id buttonBeingFakeClicked whenever someone clicks on the element with id buttonActuallyClicked.

Sign up to request clarification or add additional context in comments.

4 Comments

I tried this and doesn't seem to be working in internet explorer 6. for example I have: <textarea style="height:80px; border:0px;" name="box3" id="box3" cols="58" rows="7" class="title">FUTURE: </textarea> <script> $('#box3').click(function() { $('#link').click(); }); </script> <a id="link"><div id="test3-header" class="accordion_headings future" >FUTURE</div></a>
@DanielKellaway: Just to make sure: you have included jQuery in your page, right? IE6 is ridiculously old and it was literally the bane of web development for years. I strongly suggest you don't support it at all; you'd be doing users a favor if you can convince them to ditch it. At any rate, jQuery attempts to normalize everything for cross-browser issues, so if it doesn't work with jQuery, you might be out of luck.
That's the problem, it is an organisation with ie6 across the network and win xp, and they won't change. If I could use any other browser I would. I'm having to use virtual pc on my laptop just to even check if the coding works in ie6. Thanks for the answer. Will keep trying to see if can get it working.
@DanielKellaway: I honestly think your time is better spent lobbying them to upgrade the browser. XP is fine, but IE6 is awful. It is slow, wastes a lot of processing power, is a security nightmare, and has extremely weak support for any web development post-1998. Even something as simple as moving to IE8 (the last IE released for XP) would improve matters tremendously. Chrome, Firefox, or Opera would be even better. They'll improve productivity and reduce wasted time and energy.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.