MVRCXS
MVRCXS

Reputation: 1

.trigger("click") doesnt work

I have a ul

<ul class="nav nav-pills nav-justified" id="navTab">
   <li onclick="setTimeout(breadcrumbChange, 200);" class="active">
     <a href="#stepOne" data-toggle="tab">
       <i class="fa fa-map-marker"></i>
       <br>#rn:msg:CUSTOM_MSG_CLIENT_PROJECT_TAB#
     </a>
   </li>
   <li onclick="setTimeout(breadcrumbChange, 200);" class="disabled">
     <a href="#stepTwo" data-toggle="tab">
       <i class="fa fa-star"></i>
       <br>#rn:msg:CUSTOM_MSG_BASE_PRODUCT_SELECTION_TAB#
     </a>
   </li>
   <li onclick="setTimeout(breadcrumbChange, 200);" class="disabled">
     <a href="#stepThree" data-toggle="tab">
       <i class="fa fa-magic"></i>
       <br>#rn:msg:CUSTOM_MSG_DESIGN_STYLE_TAB#
     </a>
   </li>
   <li onclick="setTimeout(breadcrumbChange, 200);" class="disabled">
     <a href="#stepFour" data-toggle="tab">
       <i class="fa fa-gift"></i>
       <br>#rn:msg:CUSTOM_MSG_ORDER_REVIEW_TAB#
     </a>
   </li>
 </ul>

And I have a button

<div class="pull-right">
    <a class="btn btn-template-main btnNext"> 
        #rn:msg:CUSTOM_MSG_COMPLETE_ORDER_CMD#<i class="fa fa-check"></i>
    </a>
 </div>

I put an event handler to get the "button" click :

$('.btnNext').click(function() {
   $('#navTab li.active').next('li').removeClass('disabled');
   $('#navTab li.active').next('li').find('a').attr("data-toggle", "tab");
   $('#navTab li.active').next('li').find('a').trigger("click");   
});

When I click on the "button" removeclass and .attr work perfectly , but the .trigger is not working. Does anyone know why?

Upvotes: 0

Views: 92

Answers (1)

Satpal
Satpal

Reputation: 133403

.trigger() will only execute the associated event handler, It will not actually click the element. If no event handlers are assiocaited it will not perform any action.

However, You can use .get() to get the reference of underlying DOM element, then native click() can be executed.

$('#navTab li.active').next('li').find('a').get(0).click()

Upvotes: 3

Related Questions