javascript - issue on dropdown li menu -
i have following javascript , following html excerpt code. have element fantasylink id, , want when clicked, li dropdown shows doesn't anything, when run code on console, action. clicked element circled in image.
$(document).ready(function () { $('#fantasylink').on('click', function (){ $('body').find('#droplogin').click(); }); }); <li class="dropdown" id="linklogin"> <a id="droplogin" href="#" class="dropdown-toggle" data-toggle="dropdown"><b>login</b> <span class="caret"></span></a> <ul id="login-dp" class="dropdown-menu"> <li> <div class="row"> <div class="col-md-12"> <div id="message"></div> <label class="label-login">iniciar sesión con:</label> <div class="social-buttons"> <fb:login-button scope="public_profile,email" data-size="xlarge" onlogin="checkloginstate();" class="btn"> facebook </fb:login-button> </div> note: have tried using trigger, adding open class linklogin element shows, toggle class, none of them working...
you shouldn't need $('body').find('#droplogin').click()
because of .find() returns array of objects way work if did: $('body').find('#droplogin')[0].click()
however, shouldn't need that. -
$('#droplogin').click(); that should trick you. beauty of jquery , selectors if have id shouldn't need search dom it, use selector.
alternatively instead of using click event that, seems gets clicked programmatically can create simple function -
$(document).on('click', '#fantasylink', function() { droplogin(); }); var droplogin = function() { //do } 

Comments
Post a Comment