samedi 29 novembre 2014

jquery Not working properly or I'm a dummie


Vote count:

0




I'm new to programming and now learning jquery. I have to make easy Etch-A-Sketch app. I'm trying to make it in jsfiddle.net Everything is fine? but when I'm entering width and height of my Grid it's doing wrong. Example: I enter 10 (in width prompt) and 10 (in height prompt) but in result height is 20, width is 15. Here is my jquery code:



$(document).ready(function(){
$('button').click(function(){
var height = prompt("Enter your height (less than 64)");
var width = prompt("Enter your width (less than 64)");
if (height > 64){
alert("You can't make height more than 64!");
}
if (width > 64){
alert("You can't make width more than 64!");
}
for (i=0; i<height; i++){
$('#container').append('<ul></ul>');
}
for (i=0; i<width; i++){
$('ul').append('<li><li>');
}
$('li').hover(function(){
$(this).css('background-color', 'red');
});
});
});


Here is html:



<body>
<quotes>Press the button to create your own Grid</quotes><br/>
<button>New Grid</button>
<div id = "container"></div>
</body>


And here is CSS:



quotes{
margin-left: 25px;
margin-top: 10px;
}
button{
margin-left: 130px;
margin-top: 4px;
}
ul{
margin: auto;
padding: auto;
}
ul li{

list-style: none;
display: inline-block;
height: 20px;
width:30px;
border: 1px solid black;
}


It's working but in a wrong way. Where is my mistake? Help me please to understand it. Thanks for attention



asked 19 secs ago







jquery Not working properly or I'm a dummie

Aucun commentaire:

Enregistrer un commentaire