crazydev
crazydev

Reputation: 575

Put an event click on an specific item in ul in jquery

I need a help regarding jquery. Actually I have the following HTML markup:

     <ul class="accordion accordion--sm js-accordion">
            <li class="accordion__item">
                <div class="accordion__tab">
                    <h3 class="accordion__tab-title to-uppercase">
                        Customers
                    </h3>

                    <i class="material-icons accordion__tab-icon mdl-animation--default js-accordion-customer">add</i>
                </div>

                <div class="accordion__panel accordion__panel--transparent js-render-customer" style="display: none;">
                </div>
            </li>
        </ul>

I want to add a click event on the class js-accordion-customer inside the ul. The way I have done this as follows:

 $('ul.js-accordion').find('.js-accordion-customer').on('click', function () {

console.log('the icon is clicked');

But it's not working. Can someone please help ?

Upvotes: 0

Views: 35

Answers (1)

Azad
Azad

Reputation: 5264

$('ul .js-accordion-customer').click( function () {

console.log('the icon is clicked');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul class="accordion accordion--sm js-accordion">
  <li class="accordion__item">
    <div class="accordion__tab">
      <h3 class="accordion__tab-title to-uppercase">
        Customers
      </h3>

      <i class="material-icons accordion__tab-icon mdl-animation--default js-accordion-customer">add</i>
    </div>

    <div class="accordion__panel accordion__panel--transparent js-render-customer" style="display: none;">
    </div>
  </li>
</ul>

Upvotes: 1

Related Questions