Can the element in variable d be identified directly instead of looping through each function? Take a look at the DOM below:
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<script src="../jquery-ui-1.10.4.custom/js/jquery-1.10.2.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
var d = $("img", "#totaldiv");
d.each(function() {
if ($(this).attr("id") == "imgfour")
$(this).hide();
});
});
</script>
</head>
<body>
<div id="totaldiv">
<img alt="hi image one" id="imgone" src="someimage" />
<img alt="hi image two" id="imgtwo" src="someimage" />
<img alt="hi image three" id="imgthree" src="someimage" />
<img alt="hi image four" id="imgfour" src="someimage" />
<img alt="hi image five" id="imgfive" src="someimage" />
</div>
</body>
</html>
This is just for illustration purposes, my actual HTML structure is dynamic. I want to avoid using $("#totaldiv #imgfour").hide(); (or) $("#totaldiv>#imgfour").hide();