My goal is to hide the "target" div, but for some reason, it's not working as intended. When I try to hide the div with id "div1" instead of "target," it works fine. Can anyone help me figure out why I can't hide the "target" div?
<html>
<head>
<title>My example</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#hide").click(function(event){
var ele = document.getElementById("target");
ele.style.display = "none";
});
});
//myItems.length
$(document).ready(function() {
$("#driver").click(function(event){
$.getJSON('http://www.example.com/JSONV5.php', function(jd) {
var myItems = jd["items"];
for (i = 0; i < 1; i++) {
$('#div1').append('<div id="target">');
$('#div1').append('<p> Title: ' + jd["items"][i]["title"] + '</p>');
$('#div1').append('<p> Description: ' + jd["items"][i]["description"] + '</p>');
$('#div1').append('<p><img alt="" src=/uploads/' + jd["items"][i]["image1"] + '></p>');
$('#div1').append('</div>');
};
});
});
});
</script>
</head>
<body>
<p>Click on the button to load result.html file:</p>
<div id="div1" style="background-color:#cc0;">
My DIV 1
</div>
<input type="button" id="driver" value="Load Data" />
<input type="button" id="hide" value="Hide Data" />
</body>
</html>