0
how to empty or clear the content of the Div .
I have used empty() and remove() functions , but its not working.
16 odpowiedzi
+ 2
in line 40 you only need $(".actDiv").html("");
+ 2
@jonathan pizarra thank you it's working now
+ 1
jQuery:
$("div").html("");
JavaScript:
document.getElementById("DivId").innerHTML = "";
+ 1
i have tried the above code , but it's not working
+ 1
can you post your code here so we can see the real problem?
+ 1
I can't. Is it public?
+ 1
the link to the code you posted is php and there is nothing in it. What is the name of your code?
+ 1
DropdownList
+ 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
0
can you see my code ?
0
yes
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);
}
});
});
0
I have copied my JavaScript file .
0
DropdownList is my code name