I am new to jquery and I am trying to do the following: I have a page with a lot of images. I added a text box with onchange calling this function:
function filter() { var filter = $("#filter").val() $('.photo').show(); if (filter != '') $('.photo').find('.'+filter).hide(); }
The point is to show only images that have a โfilterโ somewhere in their class name.
EDIT
<a name="test"></a> <h3>Tests</h3><br /> <img class="photo livre_gang_leader.jpg" src="/images/test/livre_gang_leader.jpg" /> <img class="photo stephen_king_fatal.jpg" src="/images/test/stephen_king_fatal.jpg" /> <img class="photo livres_millenium.jpg" src="/images/test/livres_millenium.jpg" /></a> <img class="photo martin_page_stupide.jpg" src="/images/test/martin_page_stupide.jpg" /> <img class="photo Civilization-V-Title.jpg" src="/images/test/Civilization-V-Title.jpg" /> <br /><br />
EDIT
<form onSubmit="javascript:filter()"> <input type="textbox" placeholder="Filtre" id="filter" /> <input type="submit" value="filtrer"> </form><br />
source share