Reputation: 5808
I have a menu that looks like this (1 list item as an example):
<ul class="dyn makeLink" style="display: block;">
<li id="licategory_1">
<a href="/nfl-lines" title="" class="linkItem">
<strong>NFL</strong>
</a>
<span class="expCollPos" >
<span class="collapsed"></span>
</span>
<span class="expCollPos linkItem" >
<span class="collapsed"></span>
</span>
<span class="expCollPos" >
<span class="collapsed"></span>
</span>
</li>
<li id="licategory_2">
...
</li>
</ul>
Which has for some strange reason 3 spans(.expCollPos), the two first ones aren't relevant for me and I'm trying to remove ONLY them using jQuery.
I tried using:
$('.dyn li span.expCollPos:last-child').css("display", "none");
and several others - but it just removes all of the .expCollPos
classes.
Am I doing something wrong?
(I got a code that I have to edit and it looks horrable! The javascript functions are unclear and the CSS has so much "!important" that I cant find what's what. )
Upvotes: 3
Views: 4348
Reputation: 31
$('body').find('.teads-inread:not(:last)').hide();
https://jsfiddle.net/mbrasil/n0reckgv/
Upvotes: 0
Reputation: 1
Try
$(".dyn li span.expCollPos").slice(-1).hide();
$(".dyn li span.expCollPos").slice(-1).hide()
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<ul class="dyn makeLink" style="display: block;">
<li id="licategory_1">
<a href="/nfl-lines" title="" class="linkItem">
<strong>NFL</strong>
</a>
<span class="expCollPos" >
<span class="collapsed">1</span>
</span>
<span class="expCollPos linkItem" >
<span class="collapsed">2</span>
</span>
<span class="expCollPos" >
<span class="collapsed">3</span>
</span>
</li>
<li id="licategory_2">
</li>
</ul>
Upvotes: 2
Reputation: 388316
You want to hide all but the last one, so you have to say not last like
$('.dyn li').find('span.expCollPos:not(:last)').hide();
Upvotes: 8