简体   繁体   中英

how to hide skill div on close class click

how to hide div on object of div click I am adding jquery path than my html code is here as it is and than after I am apply script to delete label class="main" with span and div class close1

but it's not perform

    <label class="main ">
        <span class="tag-value">mysql </span>
        <div class="close1">X</div>
    </label>
    <label class="main ">
        <span class="tag-value">codeigniter </span>
        <div class="close1">X</div>
    </label>
    <label class="main ">
        <span class="tag-value">ajax </span>
        <div class="close1">X</div>
    </label>
    <label class="main ">
        <span class="tag-value">jquery </span>
        <div class="close1">X</div>
    </label>




        <script>
            $(function(){       
                $(".close1").click(function(){
                    $(this).parent(".main").hide();
                 });
            });
        </script>

Check that JQ lib. is in the head of you r document, also, you can probably just use .parent()

http://jsfiddle.net/Yx4EU/

           <script>
                $(function(){       
                    $(".close1").click(function(){
                        $(this).parent().hide();
                     });
                });
            </script>

If this does not work, I suggest adding a fiddle for someone to look at.

Check this out: http://jsfiddle.net/8436y/1/ In this fiddle you will notice I haven't defined the parent, since it is not necessary (in this case).

http://jsfiddle.net/8436y/5/ here I have used the .closest() to define the closest class="main" , which also works ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM