/    Sign up×
Community /Pin to ProfileBookmark

Script to change glyphicon on Accordion Nav…

I have a Bootstrap 3 accordion nav which consists of multiple repeats of this code block [U]all with their own ids[/U] #tab1, tab2 etc…

<!– New/Used Machines Tab with Dropdowns–>
<a href=”#tab1″ class=”list-group-item list-group-item-success” data-toggle=”collapse” data-parent=”#MachineMenu”><span class=”glyphicon glyphicon-triangle-right”></span>CNC MILLING<span class=”label label-info pull-right machines_available”>5</span></a>
<div class=”collapse” id=”tab1″>
<a href=”#” class=”list-group-item pl40″>DRILLING &amp; BORING<span class=”label label-info pull-right machines_available”>5</span></a>
<a href=”#” class=”list-group-item pl40″>HORIZONTAL<span class=”label label-info pull-right machines_available”>5</span></a>
<a href=”#” class=”list-group-item pl40″>OTHER<span class=”label label-info pull-right machines_available”>5</span></a>
<a href=”#” class=”list-group-item pl40″>UNIVERSAL<span class=”label label-info pull-right machines_available”>5</span></a>
<a href=”#” class=”list-group-item pl40″>VERTICAL<span class=”label label-info pull-right machines_available”>5</span></a>
</div>
<!– New/Used Machines Tab with Dropdowns END–>

I’m using the following js :

<!– jQuery to Control Glyphicons in New/Used Machinery Menu –>
<script>
$(‘#MachineMenu’).on(‘shown.bs.collapse’, function() {
$(“.glyphicon”).removeClass(“glyphicon-triangle-right”).addClass(“glyphicon-triangle-bottom”);
});

$(‘#MachineMenu’).on(‘hidden.bs.collapse’, function() {
$(“.glyphicon”).removeClass(“glyphicon-triangle-bottom”).addClass(“glyphicon-triangle-right”);

});
</script>

The problem is that this is changing the state of ALL the glyphicons in the nav, not the SINGLE ONE that has been clicked ???

How do I make the js target ONLY the clicked nav ?

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@WebnerdNov 10.2015 — You are not using anything to call out this current item. You need to assign the "real" selection using "this"

<i>
</i>$('#MachineMenu').on('shown.bs.collapse', function() {
$(".glyphicon").removeClass("glyphicon-triangle-right");
$(this).addClass("glyphicon-triangle-bottom");
});


Same with the other call.

Learn some more about current scope and "this" before posting STUPID-ASS questions.
×

Success!

Help @OnlineRocker spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...