This is my code HTML code :
<div id="exp_00" class="example">Hello 0</div>
<div id="exp_01" class="example">Hello 1</div>
<div id="exp_02" class="example">Hello 2</div>
<div id="exp_03" class="example">Hello 3</div>
<div id="exp_04" class="example">Hello 4</div>
If I’d like to hide all elements but 03, what do you suggest?
Method 1 :
var myID="03";
$('.example').hide();
$('#exp_' + myID).show();
Method 2 :
var myID="03";
$('.example').each(function() {
if($(this).attr('id').split('_')[1]==myID) {
$(this).show();
} else {
$(this).hide();
}
});
with second one, I do 1 cycle, but some split/equality operation. With the first one, also 1 cycle, but I apply the same operator (hide or show) 2 time to the same element.
What can you say about? In your opinion?
OR
Fudgey’s answer