Click link without id using javascript
Today I'd try to click link using javascript. I don't know id, only class. Have u got any ideas ?
Thanks
开发者_JS百科Link:
<a class="signIn" href="#" onclick="doLogin(); return false;"/>
use click or bind functions in jquery that will make it simple
$('.signIn').click(function(){
alert('link clicked');
});
if you want to get the link clicked programmatic you can use $('.signIn').click();
refer Click http://api.jquery.com/click/
and Bind http://api.jquery.com/bind/
if you are aware of jQuery you can do
jQuery(".signIn").click();
if not then you can try document.getElementsByTagName('a')
it will return you an array of href elements. It will be easy for you to find your HREF if you can find it in a loop and check if its having attribute class=signIn
.
精彩评论