Entry
How to call a same single method for all anchor tags ,hyperlinks,linkbuttons,buttons?
Apr 9th, 2008 20:35
ha mo, Dave Clark, vicky vilas,
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Vicky,
One way is to take advantage of event bubbling. Search this
FAQTS for JavaScript event bubbling to find out more on this subject.
The other way is that you could create collections of the tags you're
interested in and loop through that collection to attach your event
handler to all of the objects in the collection. For example:
var colLinks = document.getElementsByTagName("A");
var x, len = colLinks.length;
for (x=0; x<len; ++x)
{
colLinks[x].onclick = myhandler;
}
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.healthinhealth.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com