Hide selected id with jQuery
Hello everyone, I am stuck at part where I click a button, next which id=getOffer it hides, the button id=gotOffer shows up. In this code I have 50 buttons as you can see.
If I delete these "+i" 's code works just for first button.
Can anyone help me please? Thanks
- <script type="text/javascript">
- if (window.XMLHttpRequest)
- {// code for IE7+, Firefox, Chrome, Opera, Safari
- xmlhttp=new XMLHttpRequest();
- }
- else
- {// code for IE6, IE5
- xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
- }
- xmlhttp.open("GET","xml/20121106.xml",false);
- xmlhttp.send();
- xmlDoc=xmlhttp.responseXML;
- var x=xmlDoc.getElementsByTagName("promotion");
- for (i=1;i<(x.length=50);i++)
- {
-
- $("#getOffer"+"i").click(function () {
- $("#getOffer"+"i").hide();
- $("#gotOffer"+"i").show();
- });
- $("#gotOffer"+"i").click(function () {
- $("#gotOffer"+"i").hide();
- $("#getOffer"+"i").show();
- });
-
- document.write("<div class='oneDeal'>");
- document.write("<div class='imgDeal'>");
- document.write(x[i].getElementsByTagName("PROGRAMURL")[0].childNodes[0].nodeValue);
- document.write("</div><div class='nameDeal'>");
- document.write(x[i].getElementsByTagName("DESCRIPTION")[0].childNodes[0].nodeValue);
- document.write("</div><div class='linkDeal'>");
- document.write("<input type='button' class='offer' id='getOffer"+i+"' value='Click for Code' onclick='click()'><input type='button' class='offer' id='gotOffer"+i+"' style='display:none' onclick='click()'>");
- document.write("</div>");
- document.write("</div>");
- }
- </script>