how to empty or clear the content of the Div . | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to empty or clear the content of the Div .

I have used empty() and remove() functions , but its not working.

19th Jan 2018, 3:35 AM
Srivani Chinta
Srivani Chinta - avatar
16 Answers
+ 2
in line 40 you only need $(".actDiv").html("");
19th Jan 2018, 4:12 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 2
@jonathan pizarra thank you it's working now
19th Jan 2018, 4:15 AM
Srivani Chinta
Srivani Chinta - avatar
+ 1
jQuery: $("div").html(""); JavaScript: document.getElementById("DivId").innerHTML = "";
19th Jan 2018, 3:38 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 1
i have tried the above code , but it's not working
19th Jan 2018, 3:40 AM
Srivani Chinta
Srivani Chinta - avatar
+ 1
can you post your code here so we can see the real problem?
19th Jan 2018, 3:47 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 1
I can't. Is it public?
19th Jan 2018, 3:53 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 1
the link to the code you posted is php and there is nothing in it. What is the name of your code?
19th Jan 2018, 3:59 AM
Jonathan Pizarra (JS Challenger)
Jonathan Pizarra (JS Challenger) - avatar
+ 1
DropdownList
19th Jan 2018, 3:59 AM
Srivani Chinta
Srivani Chinta - avatar
+ 1
@srivani empty() or remove() methods are used to completely remove DOM elements, while html() method or text() method is used to change the text inside the elements
19th Jan 2018, 4:09 AM
code learner
code learner - avatar
19th Jan 2018, 3:48 AM
Srivani Chinta
Srivani Chinta - avatar
0
can you see my code ?
19th Jan 2018, 3:50 AM
Srivani Chinta
Srivani Chinta - avatar
0
yes
19th Jan 2018, 3:54 AM
Srivani Chinta
Srivani Chinta - avatar
19th Jan 2018, 3:56 AM
Srivani Chinta
Srivani Chinta - avatar
0
var products =[{ id:"1", text:"Stationary", items:[{ id:"1_1", text:"Books" },{ id:"1_2", text:"Pens" },{ id:"1_3", text:"Rubber" }] },{ id:"2", text:"Grocery", items:[{ id:"2_1", text:"Drinks" },{ id:"2_2", text:"Chocolates" },{ id:"2_3", text:"Snacks" }] }]; $(function(){ $("#item").click(function(){ var submenu = $("#submenu"); var div =$("<div class='actDiv'></div>"); if($(".actDiv").children().length>0){ // div.empty(); // $("#submenu").empty(); // div.end(); div.remove(); $("<div class='actDiv'></div>").html(""); } else{ for(var i=0; i< products.length;i++){ div.append($("<p class='subproduct'></p>").text(products[i].text)); if(products[i].items!=null){ for(var j=0; j<products[i].items.length;j++){ div.append($("<p class='subitems'></p>").text(products[i].items[j].text)); } } } $("#submenu").after(div); } }); });
19th Jan 2018, 4:06 AM
Srivani Chinta
Srivani Chinta - avatar
0
I have copied my JavaScript file .
19th Jan 2018, 4:07 AM
Srivani Chinta
Srivani Chinta - avatar
0
DropdownList is my code name
19th Jan 2018, 4:08 AM
Srivani Chinta
Srivani Chinta - avatar