Here’s HTML
<div id="taxonomylist">
<div class="item-list"><ul><li class="first"><a href="/?q=category/activity/energy" class="views-processed">Energy</a></li>
<li><a href="/?q=category/activity/energy/3-5" class="views-processed">3-5</a></li>
<li><a href="/?q=category/activity/energy/6-8" class="views-processed">6-8</a></li>
<li><a href="/?q=category/activity/energy/k-2" class="views-processed">K-2</a></li>
<li><a href="/?q=category/activity/forestry" class="views-processed">Forestry</a></li>
<li><a href="/?q=category/activity/forestry/3-5" class="views-processed">3-5</a></li>
<li><a href="/?q=category/activity/forestry/6-8" class="views-processed">6-8</a></li>
<li><a href="/?q=category/activity/forestry/k-2" class="views-processed">K-2</a></li>
<li><a href="/?q=category/activity/mining" class="views-processed">Mining</a></li>
<li><a href="/?q=category/activity/mining/3-5" class="views-processed">3-5</a></li>
<li><a href="/?q=category/activity/mining/6-8" class="views-processed">6-8</a></li>
<li class="last"><a href="/?q=category/activity/mining/k-2" class="views-processed">K-2</a></li>
</ul></div></div>
I need to hide all elements inside div except those that says THIS. I need to keep that one.
So as for regex parsing – i need it to show only those values that:
1. Start with anything
2. then have structure: structure /activity/”anything here”/”nothing here”
You can see what I mean by looking on the code above.
Flow of my logic
1. hide all li elements within particular div
2. if ‘a’ element inside li contains attribute href which is equal to /title/ then show this li element. My current code
$('li').css('display','none');
if ($('li').attr('href')=="*/activity/*/")
{
$('li').css('display','block');
}
if I do something like:
$('#div-id li').css('display','none');
then it does not work.
Im just tired, but need to finish work asap. help please.
Perhaps it solves your problem:
Check a demo at jsbin: http://jsbin.com/ozive4/2/edit
UPDATE: It was just a basic principle. Here is something more complete:
jQuery(function($) { function get() { $("div#div-id li").each(function() { var href = $("a", this).attr("href"); if ( href.match(/^.*\/activity\/.*\/$/i) ) { alert($(this).text()); } }); } $("button").click(function() { get(); }); });And the demo: http://jsbin.com/ozive4/4/edit
UPDATE: This is the regex:
And the new demo: http://jsbin.com/ozive4/6/edit