JQuery Empty Function

I am trying to completely remove the div, I filled it with PHP loading and the foreach loop, its print programs from the database, this is what the source code looks like when the page first loads

<div class="frame" id="program_list">                                       
<div class="box">
    <div class="box-holder">
        <div class="box-frame">
            <h3>Marathon</h3>                       <p>Run 26 miles around the city.</p>                                            <p>Trainer: John Doe</p>
                                                <span class="btn-program"><a href="#" tabindex="10"><em>BID PROGRAM</em></a></span>
                                            </div>
                                        </div>
                                    </div>


                                    <div class="box">
                                        <div class="box-holder">
                                            <div class="box-frame">
                                                <h3>Jumping Jacks</h3>
                                                <p>Do 400 Jumping Jacks in 15 minutes</p>
                                                <p>Trainer: Jane Doe</p>
                                                <span class="btn-program"><a href="#" tabindex="10"><em>BID PROGRAM</em></a></span>
                                            </div>
                                        </div>
                                    </div>

And I'm trying to clear the div_file_list using an empty jquery function as follows:

        function clear_programs_div()
    {
        alert("Test");
        $("program_list").empty();
    }

But it does not seem to get rid of the div. Does this function only remove inner text, not elements? Why doesn't he delete any elements inside? Any tips will help you!

+3
source share
4 answers

you need to add #before program_list

$("#program_list").empty()
+10
source

jQuery id selector needs # before the actual id. If you want to select elements according to the css class you are adding. before the class name.

$("#program_list").empty()
+2

:

$("div#program_list").remove();

remove() div id 'program_list' , .

empty() div , div

. jQuery

+2

In jQuery, if you want to access an element with an id, you must use #.

For example: $("#program_list").empty()or$("#program_list").delete()

However, if you want to access an element of the class, you must use .

For example: $(".program_list").empty()or$(".program_list").delete()

C $("#program_list").empty()your div will be completely omitted

0
source

Source: https://habr.com/ru/post/1771566/


All Articles