Hello
I'm trying to do an easy filter script to show the elements I want to see depending the option I've chosen. I don't want to use an external script. I'd like to do it by myself.
On the one hand, I have the option in two lists
- <ul class =" provincias ">
- <li data-provfil =" 6 ">Text</li>
- ...
- </ul>
- <ul class =" categorias ">
- <li data-catfil =" 6 ">Text</li>
- ...
- </ul>
and, on the other hand, I've the elements:
- <section>
- <article>
- <header>
- <h4>
- <span class="cat" data-cat="1">Categy 1</span>
- ....
- in
- <span class="prov" data-prov="5">Province 1</span>
- ....
- </h4>
- </header>
- </article>
- ...
- </section>
I used '
....' in order to tell the element may repeat.
And, finally, the jQuery Script is
- <script>
- $(document).ready(function() {
- $('article')
- .mouseenter(function() {
- $( this ).css('opacity','0.5');
- })
- .mouseleave(function() {
- $( this ).css('opacity','1');
- })
- .click(function(){
- alert('show the details of ' + $(this).find('h2').text());
- });
- $('aside div ul li')
- .click(function(){
- if($(this).data('provfil')){
- var iddata = 'prov';
- var actprov = $(this).data('provfil');
- }else{
- var iddata = 'cat';
- var actprov = $(this).data('catfil');
- }
-
- if(!$(this).children().hasClass('quitar-filtro')){
- $(this).append(' <span class="quitar-filtro">X</span>');
- $(this).show().siblings().hide();
-
- $("[data-"+iddata+"!="+actprov+"]")
- .closest('article')
- .hide(1000);
-
- $("[data-"+iddata+"="+actprov+"]")
- .closest('article')
- .show(1000);
-
- }else{
- $(this).remove();
- $(this).closest('ul').children().show();
-
- $("[data-"+iddata+"!="+actprov+"]")
- .closest('article')
- .show(1000);
- }
- });
- });
- </script>
I'm sure is very basic.
What problem am I having?
1. When I restore the elements (clicking on .quitar-filtro) the list elements don't appear again.
2. When I click on .quitar-filtro the article elements appear again ignoring the other filter applied
3. and finally, I'd really like to get a more visual attractive effect than show(1000) and hide(1000) for the article elements.
Could you please help me?
I'd be very grateful for some advice
THANKS