Untitled
unknown
plain_text
3 years ago
4.6 kB
9
Indexable
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.custom-table {
width: 100%;
}
.table-head-row {
display: flex;
width: 91%;
background: red;
}
.row-container {
width: 100%;
max-height: 300px;
overflow-y: scroll;
background-color: green;
}
.table-row {
display: flex;
width: 91%;
}
.table-head-row>.head-item {
border-right: 1px solid #fff;
}
.table-head-row>.head-item:nth-child(1),
.table-row>.cell:nth-child(1) {
width: 24.625%;
}
.table-head-row>.head-item:nth-child(2),
.table-row>.cell:nth-child(2) {
width: 26.625%;
}
.table-head-row>.head-item:nth-child(3),
.table-row>.cell:nth-child(3) {
width: 22.625%;
}
.table-head-row>.head-item:nth-child(4),
.table-row>.cell:nth-child(4) {
width: 24.625%;
}
.table-head-row>.head-item:nth-child(5),
.table-row>.cell:nth-child(5) {
width: 1.5%;
}
.table-head-row>.head-item:nth-child(5) {
background-color: #fff;
}
.cell>select {
width: 100%;
}
.table-row>.cell>.cross {
width: 1.5%;
padding-left: 1em;
display: block;
}
.custom-table>.row-container>div.table-row:nth-child(1)>.cell>.cross {
display: none;
}
</style>
</head>
<body>
<div style="width:100%">
<button id="addMore" rowToDuplicateID="tableRow1" appendToDivID="rowContainer">add more</button>
<div class="custom-table" id="customTable">
<div class="table-head-row">
<div class="head-item">Delivery Location:Onsite</div>
<div class="head-item">Delivery location:Offshore</div>
<div class="head-item">Business hours</div>
<div class="head-item">Language Support</div>
<div class="head-item"></div>
</div>
<div class="row-container" id="rowContainer">
<div class="table-row" id="tableRow1">
<div class="cell">
<select name="select1" id="" class="table-select">
<option value="--Select--">--Select--</option>
</select>
</div>
<div class="cell">
<select name="select1" id="" class="table-select">
<option value="--Select--">--Select--</option>
</select>
</div>
<div class="cell">
<select name="select1" id="" class="table-select">
<option value="--Select--">--Select--</option>
</select>
</div>
<div class="cell">
<select name="select1" id="" class="table-select">
<option value="--Select--">--Select--</option>
</select>
</div>
<div class="cell">
<span class="cross delete-row">X</span>
</div>
</div>
</div>
</div>
</div>
</body>
<script src="https://code.jquery.com/jquery-3.6.3.min.js"
integrity="sha256-pvPw+upLPUjgMXY0G+8O0xUf+/Im1MZjXxxgOcBQBXU=" crossorigin="anonymous"></script>
<script>
function addMoreRows(rowToDuplicateID, appendToDivID) {
let clonedRow = $("#" + rowToDuplicateID).clone()
let newID = clonedRow.attr('id') + (Math.random() + 1).toString(36).substring(2);
clonedRow.attr('id', newID)
clonedRow.appendTo("#" + appendToDivID)
}
$("#addMore").click(function () {
let rowToDuplicateID = $(this).attr('rowToDuplicateID')
let appendToDivID = $(this).attr('appendToDivID')
addMoreRows(rowToDuplicateID, appendToDivID)
$('.delete-row').off('click');
$(".delete-row").click(function () {
$(this).parent().remove()
})
})
$(".delete-row").click(function () {
$(this).parent().remove()
})
</script>
</html>Editor is loading...