Consider this HTML:
<div id=plan>
<div id="plan-1" class='plan-hide'>One</div>
<div id="plan-2" class='plan-hide'>Two</div>
<div id="plan-3">Three</div>
<div id="plan-4" class='plan-hide'>Four</div>
</div>
I want to hide all the plans (plan-1, plan-2, plan-3, plan-4) in the #plan
I have used regex [id^=plan-] but I believe its slow.
$("#slider").slider({
range: "min",
min: 0,
max: 4
}, {
slide: function( event, ui ) {
$("[id^=plan-]").addClass('plan-hide');
$("#plan-" + (ui.value+1)).removeClass('plan-hide');
},
});
What is alternative way?
If you’re trying to add the class to all the elements in the container except the one that matches the ui value + 1, targeting all siblings is probably faster:
or even just:
and probably fastest: