I have two questions:
I have an assignment, where I populate a square grid with a lot of small square divs (think pixels). They should not have any margins - and they don't, as long as there are no more of them than 51 in a row. Then suddenly they get margins, and overflow my grid (a wrapper div). I've reset all the margins in the css to 0, and even used a negative margin, and it still happens. Why is that?
Second thing is some inconsistency when calling a JS function on a button click. It goes like this: when I use jQuery to bind that function to a button (the
on()
function), it works in JSfiddle, but IT DOES NOT WORK in the browser (I use chromium). I have to useonclick
in the button's html tags for it to work. Again, why is that?
Here's the code parts I think could be the problem:
function reset() {
var new_size = prompt('Enter a new amount of squares in a row');
populate(new_size);
}
$('#reset').on('click', function () {
reset();
})
This should make the reset work on the button, and it does work in jsfiddle, but not in the browser.
This works for the browser:
<input id="reset" onclick='reset();' type="submit" value="Reset">
Here's some css:
* {
margin-bottom: -4px;
}
.wrapper {
width: 960px;
height: 960px;
margin: 0px auto;
border-style: solid;
border-width: 1px;
}
.square {
border-style: none;
border-width: 1px;
display: inline-block;
background-color: white;
}
When I tried to reset margins to 0, it didn't work either, I had to use negative one.
Thanks.