...

View Full Version : how to start a function when click a memeber of a class



cdzhang
03-27-2012, 05:02 AM
I have a question: look at the following html code:
/****html***/
<div class='class1'>text1</div>
<div class='class1'>text2</div>
<div class='class1'>text3</div>
......
/**html***/
If I want to change the background color of the textn by clicking it, what should I do instead of inserting "onclick='someFunction()'" in every div?

Dormilich
03-27-2012, 06:48 AM
there are several possibilities.
- attach the event to the parent element and execute the code on the target element (Event.target).
- attach the event to each <div> in JavaScript (assign inside a loop)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum