Как заменить элемент, который является объектом span, на другой набор кнопок?
просто очистите содержимое и замените его новым набором кнопок:
$("#firstSet").contents().remove();
var i=1;
for(;i<=10;i++){
$('<div/>', {
'class':'btn btn-default',
'html':'<span>Element'+i+'</span>'
}).appendTo('#firstSet');
}
в вашем случае, если я правильно понял ваш вопрос, это выглядит примерно так:
обратите внимание, что некоторые идентификаторы повторяются (# option1, # option2 ....).
<!DOCTYPE html>
<html>
<head>
<title></title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<br/>
<div id="set0" style="border: solid 1px black">
<br />
<div class="w3-display-container col-md-12 col-sm-12 col-xs-12" style="position:relative;top:1px;bottom:0;">
<!--<div class="container">-->
<div class="row">
<div class="btn-group btn-group-justified" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" name="options" id="option01" autocomplete="off" onchange="dataSegment(0)" checked>
</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option02" autocomplete="off" onchange="dataSegment(1)">
</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option03" autocomplete="off" onchange="dataSegment(2)">
</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option04" autocomplete="off" onchange="dataSegment(3)">
</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option05" autocomplete="off" onchange="dataSegment(4)">
</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option06" autocomplete="off" onchange="dataSegment(5)">
</label>
</div>
</div>
</div>
</div>
<br/>
<div id="set1" style="border: solid 1px black">
<br />
<div class="w3-display-container col-md-12 col-sm-12 col-xs-12" style="position:relative;top:1px;bottom:0;">
<!--<div class="container">-->
<div class="row">
<div class="btn-group btn-group-justified" data-toggle="buttons">
<label class="btn btn-default">
<input type="radio" name="options" id="option11" autocomplete="off" onchange="dataSegment(0)" checked>
</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option12" autocomplete="off" onchange="dataSegment(1)">
</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option13" autocomplete="off" onchange="dataSegment(2)">
</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option14" autocomplete="off" onchange="dataSegment(3)">
</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option15" autocomplete="off" onchange="dataSegment(4)">
</label>
<label class="btn btn-default">
<input type="radio" name="options" id="option16" autocomplete="off" onchange="dataSegment(5)">
</label>
</div>
</div>
</div>
</div>
<script>
$(document).on('click', '.btn btn-default', function(){
alert(this.innerHTML);
});
for(var j=0; j<2 ; j++){
$("#set" + j).contents().remove();
var i=1;
for(;i<=10;i++){
$('<div/>', {
'class':'btn btn-default',
'html':'<span>Element'+i+'</span>'
}).appendTo("#set" + j);
}
}
</script>
<style>
.myClass{
background:#ccc;
margin:10px;
cursor:pointer;
}
</style>
</body>
</html>