javascript - Call onclick event of some other tag -
i need call onclick event of 1 tag when other hyperlink clicked.
<div class="a"><a href=".." onclick=".?." > // tag1 </div> <span class="b"><a href=".." onclick="echo('hi');" > // tag2 </span>
thus whenever onclick event of tag1 gets executed, should nothing call onclick event of tag 2. how do this? (sorry, new javascript).
document.getelementsbyclassname("a")[0].onclick = function () { document.getelementsbyclassname("b")[0].children[0].click(); }
that should it.
you can use (i fixed html well. missing </a>
):
<div class="a"><a href=".." onclick="document.getelementsbyclassname('b')[0].children[0].click();">link text</a></div> <!-- tag 1 --> <span class="b"><a href=".." onclick="alert('hi')">link 2 text</a></span> <!-- tag 2 -->
Comments
Post a Comment