i have a page around 500 div as below.
<div onclick='test()' class='test>
<ul class='innermenu'>
<li>1</li>
.....
</ul>
</div>
when the test function is called it need to hide the menu (innermenu) who calls that function.
my problems are
-
uniquely identify the div without using id
-
How to hide only the particular ul alone.
OK, first the quick fix, though it is not the best way to use JS on your page:
Change the call to this:
Then, in test, use this:
This will hide just the child
ulof thedivthat is clicked.A better way
OK, for the longer answer. Either attach the events after the fact using
attachEventandaddEventListeneror use a library like jQuery to help you out. Here is the raw solution:Set up your HTML this way (no
onclick):And then at the very end of your HTML put this:
Now, you don’t have JavaScript code in your HTML, and you can get rid of the extra parameter on the
testfunction.