1

I have a block of HTML that looks like this:

<div data-toggle="collapse" data-parent="#groupOptions" data-target="#group" aria-expanded="true" aria-controls="group" class="collapsable-group-header">
  <h3><span class="glyphicon glyphicon-chevron-right toggle"></span> Group</h3>
</div>

This HTML is using Bootstrap's collapse control. The behavior works fine. I'm now trying to change the glyphicon from right to down. To do that, I have the following:

$('#group')
  .on('show.bs.collapse', function () { 
    var $toggle= $('#group > .toggle');
    $toggle.removeClass('glyphicon-chevron-right');
    $toggle.addClass('glyphicon-chevron-down');
    console.log($toggle.html());
  })
  .on('hide.bs.collapse', function() { alert('hiding...'); })
;

Unfortunately, this is not working. My console.log statements are printing undefined. Yet, if I do console.log($toggle) I see an element. What am I missing?

Thank you!

1
  • is the alert working?... Commented Jan 21, 2015 at 16:41

2 Answers 2

4

Change

$('#group > .toggle');

To

$('[data-target=#group] .toggle');

I don't see anything with an id set to group.

Also, .toggle isn't the immediate child of the parent so get rid of >.

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

Comments

0

The result returned by jQuery is an array. Use $toggle[0].removeClass... instead.

1 Comment

If your intention is to target a single element that is... :-)

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.