There are some Tabs formed using the widget in YII2.

<li class="active"> <a href="#tabs-document-repairs-tab1" data-toggle="tab" ariaexpanded="true">ЗИП</a> </li> 

How can you catch a click with only this data?

  $('body').on('click', 'ЧТО НУЖНО ВПИСАТЬ СЮДА?', function() { //Код }); 

    2 answers 2

     $('body').on('click', "a[href='#tabs-document-repairs-tab1']", function() { console.log($(this)); }); 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <li class="active"> <a href="#tabs-document-repairs-tab1" data-toggle="tab" ariaexpanded="true">ЗИП</a> </li> 

    • Somehow you have everything difficult to do. I made it easier. - ʞɔᴉN ɹǝꓥ
    • And the error takes off. - ʞɔᴉN ɹǝꓥ
    • @Ver Nick, what's the mistake? - Bert
    • and you run :) - ʞɔᴉN ɹǝꓥ
    • @Ver Nick, I have no mistake, can I tell you exactly which error? - Bert

    The easiest way without jQuery, classic javascript:

     function func(){ alert("Нажата ссылка!"); } 
     <li class="active"> <a href="#tabs-document-repairs-tab1" data-toggle="tab" ariaexpanded="true" onclick = "func()">ЗИП</a> </li> 

    The onclick event occurs when you left-click on the element to which the onclick attribute is added.

    • And minus then why? - ʞɔᴉN ɹǝꓥ
    • one
      The li element is formed using the widget on YII2. I do not think that there is an opportunity to arbitrarily change the attributes of the element. If there is such an opportunity, indicate this in the answer. - Stepan Kasyanenko
    • @StepanKasyanenko Well, I made it the easiest way for a newbie. - ʞɔᴉN ɹǝꓥ
    • Whether the vehicle can use your code - that is the question! - Stepan Kasyanenko