Your open source for Development and Design

Javascript click() method

Filed under: JavaScript — Adi @ 8:04 am June 6, 2009

Javascript has evolved into a great web programming language over the last few years with its compatibility getting much greater then it was and with the versatility of the script.

This week I came back to a script I wrote some time ago using a frame work. The script basically allowed the visitor to click next or previous and scroll through a list element. Although dynamic HTML is pretty awesome it can be hard to maintain.

Due to requirements the scroll er has had to be automated as well as respond to a users click which it wasn’t built for, At first it may need to be re written from scratch but then I came across the click() method.

Click() basically simulates a users click on a button in javascript. Unfortunately it only works with form button elements and not with elements such as hyperlinks.

If you need to simulate the click of another type of element I would suggest making a button and giving it the style display:none;

example usage

getElementByID(‘someid’).click();

Switch to our mobile site