I would like to be able to remove any isolated item (cherry pick)in the following array and remove it so it won't display in the dom. I would like to do this by it's index number.
For example I can log it by
console.log(div.questions[2]);
what can I use to remove div.questions[2] from the dom without a refresh?
Also can this be done by adding an event to a button so it would change which ones were displayed without having to refresh the screen?
Ultimately what I'm trying to do do is have some questions go down a path and then it would skip to the rest of the regular questions.
HTML
<html>
<head>
<title>AlsSate Quiz Prototype</title>
<link href ="style.css" rel ="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lato" rel="stylesheet">
<script src="jquery-3.2.1.min.js"></script>
<script src = "main.js"></script>
</head>
<body>
<div class="container">
</div>
</html>
Code (from main.js)
$( document ).ready(function() {
var div = {
questions: [
{
title: "what vehicle",
description: "1 Lorem ipsum dolor sit amet, consectetur adipiscing",
btn1:"car",
btn2:"motorcycle"
},
{
title: "what brand",
description: "2 Lorem ipsum dolor sit amet, consectetur adipiscing",
btn1:"honda",
btn2:"harley"
},
{
title: "what car",
description: "3 Lorem ipsum dolor sit amet, consectetur adipiscing",
btn1: "chevy",
btn2: "ford"
},
{
title: "how many miles do you drive a week",
description: "4 Lorem ipsum dolor sit amet, consectetur adipiscing",
btn1: "500",
btn2: "100"
}
]
};
//div.questions=div.questions.slice(0,3);
//div.questions=div.questions.splice(1,3);
$.each(div.questions,function(i,x){
$('.container').append('<div class="wrapper"><h3>'+x.title+'<p>'+x.description+'</p></h3> '+x.btn1+' '+x.btn2+'</div>')
})
console.log(div.questions[0]);
//var hide =div.questions[1]
//hide.hide();
});//end ready