cesarcesar Posted September 16, 2008 Share Posted September 16, 2008 i need to simulated having clicked on a link with JavaScript. As you will see in my stripped down example the resulting function from the click is a window.addEvent() action. Thanks for the help. js code - window.addEvent('domready', function() { expandCollapse(); } function expandCollapse(){ $('expand').addEvent('click', function(){ // do something } } html code - <a id="expand" href="javascript:void(0);">open all</a> i have tried this but id didnt work - document.getElementById('expand').click(); What is the code to make the window.addEvent() fire? *expand* must be part of it. Thank you. Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 16, 2008 Share Posted September 16, 2008 Do you mean the onClick event handler? Google it. Quote Link to comment Share on other sites More sharing options...
cesarcesar Posted September 16, 2008 Author Share Posted September 16, 2008 thanks for your incredible help. Been there done that. Didn't fine a great solution. Maybe you could actually help by pointing to a site reference instead of just raising your post count. Quote Link to comment Share on other sites More sharing options...
cesarcesar Posted September 16, 2008 Author Share Posted September 16, 2008 Thanks to Fang - Working Solution - function fireOnclick(objID) { var target=document.getElementById(objID); if(document.dispatchEvent) { // W3C var oEvent = document.createEvent( "MouseEvents" ); oEvent.initMouseEvent("click", true, true,window, 1, 1, 1, 1, 1, false, false, false, false, 0, target); target.dispatchEvent( oEvent ); } else if(document.fireEvent) { // IE target.fireEvent("onclick"); } } Quote Link to comment Share on other sites More sharing options...
CroNiX Posted September 17, 2008 Share Posted September 17, 2008 It looks like you are using mootools. Here is the info for 'fireEvent': http://mootools.net/docs/Element/Element.Event#Element:fireEvent Quote Link to comment Share on other sites More sharing options...
cesarcesar Posted September 17, 2008 Author Share Posted September 17, 2008 thanks cronix. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.