I am new to jQuery and need some help with filtering classes. The user can select one of nine buttons to select the types of events to show / hide. Click the color and only events with this color show, and the rest will be hidden. Click "all" and all events will show not a single hidden one. All events start with display:block.
Examples of control buttons:
<li class="all" id="all-events"><a href="#" onclick="showEvents('event-all')">
<img src="swatch-all.png" alt="" /></a></li>
<li class="red" id="red-events"><a href="#" onclick="showEvents('event-red')">
<img src="swatch-red.png" alt="" /></a></li>
<li class="blue" id="blue-events"><a href="#" onclick="showEvents('event-blue')">
<img src="swatch-blue.png" alt="" /></a></li>
Events are pulled from the database using php and look like this:
<div id="bigCal">
<p class="all"><a href="http://foo.com" title="All event">All events</a></p>
<p class="blue"><a href="http://bar.com" title="Blue event">Blue event</a></p>
<p class="red"><a href="http://foobar.com" title="Red event">Red event</a></p>
</div>
I have been working on jQuery for two days! Not sure whether to use .filtereither .hasClassor .is. None of this works. The simplest one I tried was:
function showEvents(color) {
($('p').hasClass(color)) ? this.style.display="block" : this.style.display="none";
}
Another attempt that did nothing was
function showEvents(color){
$("p[className*='event-']").css('display', 'none');
$("p[className=color]").css('display', 'block');
if ($("p[className='event-all']"))
$("p[className*='event-']").css('display', 'block');
}
Any help would be appreciated!