Manually trigger bootstrap event navbar menu click event

I have a requirement when I need to manually trigger the click event for the boot menu (v3.3.5). I tried to click the li event, as well as the tag inside li, but they do not work. below is my code:

<div id="navbar" class="collapse navbar-collapse">
    <ul class="nav navbar-nav">
        <li role="presentation"><a href="index.html"><span class="menuicon home"></span><span class="menutittle">Home</span></a></li>
        <li id="li_contact"><a href="contact.html"><span class="menuicon contact"></span><span class="menutittle">Contact</span></a></li>
        <li id="li_watsNew"><a href="wats-new.html"><span class="menuicon fingerprint"></span><span class="menutittle">What New</span></a></li>

        /// etc. . . .

JQuery Code:

$('#li_watsNew').click(); //doesn't fire

OR

$('#li_watsNew a').click(); //doesn't fire

Please help me with this.

+4
source share
1 answer

This line of code will lead the user to the location indicated by <a>:

window.location = $('#li_watsNew a').attr('href');

This will also trigger onclick events:

$('#li_watsNew a')[0].click();

, jQuery click. . $()[0] jQuery DOM ( ). jQuery $().get(0), $()[0]

+2

All Articles