我想使用jQuery删除页面的主体,但是从该主体中获取一个div并将其作为唯一显示在页面上的div
<body>
<div id="box1"></div>
<div id="box2"></div>
<div id="box3">CLONE AND APPEND ME AS ONLY DIV TO SHOW IN BODY</div>
<div id="box4"></div>
</body>
我尝试了这个,但没有奏效。我确定我需要先克隆它,然后替换?
$('body').replaceWith('#box3');
答案 0 :(得分:1)
更改为:
public class Person
{
private String name;
private int age;
public Person()
{
name = "No name yet";
age = 0;
}
public Person(String userName, int userAge)
{
name = userName;
age = userAge;
}
public static Person createAdult(String name, int age)
{
Person newPerson = new Person("An adult", 21);
return newPerson;
}
public String getName()
{
return name;
}
public int getAge()
{
return age;
}
public void setName(String first, String last)
{
name = first + last;
}
public void setName(String wholeName)
{
name = wholeName;
}
public void setAge(int userAge)
{
age = userAge;
}
public static Person createToddler(String name, int age)
{
Person Toddler = new Person("A toddler", 2);
return Toddler;
}
public static Person createPreschooler(String name, int age)
{
Person Preschooler = new Person("A preschooler", 5);
return Preschooler;
}
public static Person createAdolescent(String name, int age)
{
Person Adolescent = new Person("An adolescent", 9);
return Adolescent;
}
public static Person createTeenager(String name, int age)
{
Person Teenager = new Person("A teenager", 15);
return Teenager;
}
}
$('body').replaceWith($('#box3'));
答案 1 :(得分:1)
您需要更新
<!-- Add the extra clearfix for only the required viewport -->
<div class="clearfix visible-xs-block"></div>
到
$('body').replaceWith('#box3');
供参考 - http://plnkr.co/edit/QNv6cdkGFzRXjOZ9XYPX?p=preview
请注意你用文字而不是html替换它。此外,您可以简单地将其替换为没有克隆的元素。
答案 2 :(得分:1)
你可以试试......
$('div:not(#box3)').remove();