<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<div id="form">
<input id="Input" placeholder="Place your task here" type="text">
<select id="prioritySelect">
<option value="1" >Urgent</option>
<option value="2" >Critical</option>
<option value="3" selected>Normal</option>
<option value="4" >If You Can</option>
</select>
<button id="addButton" type="submit">Add</button>
</div>
<ul id="list">
</ul>
</body>
</html>
* {
margin: 0;
padding: 0;
}
#form{
margin: 30px 0 0 20px;
padding: 5px 0 15px 15px;
border-bottom: black solid 3px;
}
input{
margin-left: 15px;
width: 50%;
font-size: 16px;
}
select{
margin-left: 15px;
width: 10%;
font-size: 16px;
}
button{
padding: 5px;
font-size: 16px;
margin-left: 15px;
border-radius: 5px 5px 5px 5px;
}
ul{
margin: 20px 0 0px;
}
li{
position: relative;
float: left;
list-style-type: none;
margin-left: 15px;
padding: 12px 8px 12px 40px;
width: 80%;
}
span{
float:right;
right: 100px;
width: 100px;
}
.done{
color: gray;
text-decoration: line-through;
}
document.addEventListener("DOMContentLoaded", function () {
var add = document.getElementById("addButton");
var task = document.getElementById("Input");
var list = document.getElementById("list");
var body = document.querySelector("body");
var form = document.querySelector("#form");
//add first
(function () {
var newTask1 = document.createElement("li");
newTask1.dataset.priority = "3";
var all = document.querySelectorAll("li");
var index = all.length;
for (var i = 0; i < all.length; i++) {
if (parseInt(newTask1.dataset.priority) < parseInt(all[i].dataset.priority)) {
index = i;
break;
}
}
list.insertBefore(newTask1, all[index]);
var taskName = document.createElement("h3");
newTask1.appendChild(taskName);
taskName.innerHTML = "Register to Full Stack Web Course";
var priorSpan = document.createElement("span");
taskName.appendChild(priorSpan);
priorSpan.innerHTML = "Normal";
taskName.style.color = "green";
taskName.addEventListener("click", function () {
taskName.classList.add("done");
priorSpan.classList.add("done");
});
})();
//add second
(function () {
var newTask1 = document.createElement("li");
newTask1.dataset.priority = "2";
var all = document.querySelectorAll("li");
var index = all.length;
for (var i = 0; i < all.length; i++) {
if (parseInt(newTask1.dataset.priority) < parseInt(all[i].dataset.priority)) {
index = i;
break;
}
}
list.insertBefore(newTask1, all[index]);
var taskName = document.createElement("h3");
newTask1.appendChild(taskName);
taskName.innerHTML = "Attend Selection Day";
var priorSpan = document.createElement("span");
taskName.appendChild(priorSpan);
priorSpan.innerHTML = "Critical";
taskName.style.color = "orange";
taskName.addEventListener("click", function () {
taskName.classList.add("done");
priorSpan.classList.add("done");
});
})();
//add third
(function () {
var newTask1 = document.createElement("li");
newTask1.dataset.priority = "4";
var all = document.querySelectorAll("li");
var index = all.length;
for (var i = 0; i < all.length; i++) {
if (parseInt(newTask1.dataset.priority) < parseInt(all[i].dataset.priority)) {
index = i;
break;
}
}
list.insertBefore(newTask1, all[index]);
var taskName = document.createElement("h3");
newTask1.appendChild(taskName);
taskName.innerHTML = "Go see X-Men apocalypse movie";
var priorSpan = document.createElement("span");
taskName.appendChild(priorSpan);
priorSpan.innerHTML = "If You Can";
taskName.style.color = "blue";
taskName.addEventListener("click", function () {
taskName.classList.add("done");
priorSpan.classList.add("done");
});
})();
//Add task
add.addEventListener("click",addFunction);
document.getElementById("Input")
.addEventListener("keyup", function(event) {
event.preventDefault();
if (event.keyCode == 13) {
document.getElementById("addButton").click();
}
});
function addFunction () {
if (task.value.length >= 6 &&
task.value.length <= 42) {
//Add task to the list
var newTask = document.createElement("li");
var x = document.getElementById("prioritySelect").selectedIndex;
newTask.dataset.priority = document.getElementsByTagName("option")[x].value;
console.log(document.getElementsByTagName("option")[x].value);
var all = document.querySelectorAll("li");
var index = all.length;
for (var i = 0; i < all.length; i++) {
if (parseInt(newTask.dataset.priority) < parseInt(all[i].dataset.priority)) {
index = i;
break;
}
}
for (var j = index - 1; j >= 0; j--) {
if (parseInt(newTask.dataset.priority) == parseInt(all[j].dataset.priority)) {
if(task.value.localeCompare(all[j].innerText)==-1) index = j;
}
}
list.insertBefore(newTask, all[index]);
var taskName = document.createElement("h3");
newTask.appendChild(taskName);
taskName.innerHTML = task.value;
var priorSpan = document.createElement("span");
taskName.appendChild(priorSpan);
priorSpan.innerHTML = newTask.dataset.priority;
if(priorSpan.innerHTML == '1'){
priorSpan.innerHTML = 'Urgent';
taskName.style.color = "red"
}
if(priorSpan.innerHTML == '2'){
priorSpan.innerHTML = 'Critical';
taskName.style.color = "orange";
}
if(priorSpan.innerHTML == '3'){
priorSpan.innerHTML = 'Normal';
taskName.style.color = "green";
}
if(priorSpan.innerHTML == '4'){
priorSpan.innerHTML = 'If You Can';
taskName.style.color = "blue";
}
//Mark completed in grey
taskName.addEventListener("click", function () {
taskName.classList.add("done");
priorSpan.classList.add("done");
});
task.value = "";
document.getElementById("prioritySelect").selectedIndex = "2";
} else {
event.preventDefault();
alert("Task should have from 6 to 42 characters");
}
}
});
Output
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |