0

I have some divs with same .hour_slots_available named class. and also contained some disabled divs with .hour_slots_disabled named class which are change with response from database.

Now I want to change these .hour_slots_available divs with .slot_activated class when I click.

But when I click these .hour_slots_available divs then its changed with .slot_activated but also changed those disabled divs with selected divs

Here is html code

<li><div id="12_01" class="hour_slots_available" ><span class="hour_tag">12:00 - 01:00</span></div></li>
<li><div class="hour_slots_available" id="01_02"><span class="hour_tag">01:00 - 02:00</span></div></li>
<li><div class="hour_slots_available" id="02_03"><span class="hour_tag">02:00 - 03:00</span></div></li>
<li><div class="hour_slots_available" id="03_04"><span class="hour_tag">03:00 - 04:00</span></div></li>
<li><div class="hour_slots_available" id="04_05"><span class="hour_tag">04:00 - 05:00</span></div></li>

and here is my jquery code

$(".hour_slots_available").click(function () {
        $(this).toggleClass("slot_activated");
});

here is image of output

enter image description here

please guide me where i'm wrong..!

2
  • $(".hour_slots_available").click(function () { if($(this).hasClass('hour_slots_disabled')) { return; } $(this).toggleClass("slot_activated"); }); Try this! Commented Mar 5, 2017 at 7:19
  • its working.. thanks a lot bro @KalpeshSingh Commented Mar 5, 2017 at 7:22

1 Answer 1

1

Try this:

$(".hour_slots_available").not(".hour_slots_disabled").click(function () {
        $(this).toggleClass("slot_activated");
});
Sign up to request clarification or add additional context in comments.

1 Comment

That first one is working and Thanks for another solution :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.