Hi guys i am new to jquery and i have two doubts to ask from my coding..
here is my XHTML coding along with my JQUERY and CSS
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://xmlns.jcp.org/jsf/html">
<h:head>
<title>Test</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<meta name="viewport" content="width=device-width"/>
<style>
#filterpanel{
position: absolute;
top: 50%;
left: 0;
width: 99%;
height: 20%;
background-color: azure;
border: 4px solid black;
border-radius: 12px;
overflow-x: scroll;
}
</style>
</h:head>
<h:body>
<div id="filterpanel"></div>
<script>
$(document).ready(function(){
for (var i = 0; i < 6; i++) {
var s=$('<div id="filterinfo'+i+'" ><div id="imgclose'+i+'" style="position: absolute; right:0;top: 0;cursor: pointer;" ><img src="images/close.png" width="20px" height="20px"/></div></div>').css({"text-align":"center","background-color":"black","color":"white","position":"relative","width":"16%","height":"98%", "border-radius":"16px","top":"1%","float":"left","left":"0.5%","margin-left":"1%"});
s.appendTo("#filterpanel");
$("imgclose"+i).click(function(){
alert("clicked");
$("filterinfo"+i).hide();
});
}
});
</script>
</h:body>
</html>
The thing is all my div's are generated successfully with particular id's as i require ,but what happens is if my value goes above 5 for i , the generated div (i.e) filterinfo6 gets displayed below filterinfo1 instead of right side of filterinfo5 in my main div filterpanel, though i have given overflow-x as scroll for the main div.
My second doubt is that when i click on the imgclose div, the click function does not work ... i really need to close the particular div (i.e) if user clicks on the imgclose4 then the particular div filterinfo4 should be removed from my main div filterpanel .... so far what i have tried is not working .... can anyone help me with this please .
Here's a demo: http://jsfiddle.net/3XwpG/
Thanks in advance.