I can't get my "target" div to be hidden. When I change the div to hide to "div1" it works, but that is not what I want. Can anyone see why I can't hide "target" div?
<html>
<head>
<title>My sample</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;">
DIV 1
</div>
<input type="button" id="driver" value="Load Data" />
<input type="button" id="hide" value="Hide Data" />
</body>
</html>
targetin a loop, and ID's are unique. Secondly, you can't split elements acrossappend()calls, you have to insert "whole" elements, right now you are hiding the first element with the IDtarget, but that element has no children.