1

I have five divs:

<div class="tip tip-1 activeTip"></div>
<div class="tip tip-2"></div>
<div class="tip tip-3"></div>
<div class="tip tip-4"></div>
<div class="tip tip-5"></div>

I would like to use the jQuery on click event to add the activeTip class to a div and also remove it from the div it is currently set on. So only one div should have the activeTip class at a time.

Thanks

1
  • Start with binding click event handler. Commented Dec 24, 2016 at 20:02

1 Answer 1

4

following will do the job if you want click event on these divs

$(".tip").click(function(){
  $(".activeTip").removeClass("activeTip");
  $(this).addClass("activeTip");
})

if you want the click event in some other place, you have to put data tag in that and add class depend on the data value of that element

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.