In my code I am pulling a data-attribute called grid size from the HTML. When grid size is pulled through I want to write a statement that says if the value is “large” then the x and y co-orginates are… and if the value is “small” then the x and y co-ordinates are… I have given it a go but I can’t get it working. Can someone show me where I am going wrong?
Here is the statement that pulls it from the HTML
$('li[data-number-input],li[data-completion-number]').each(function(){
numberInput.push($(this).attr('data-number-input'));
completionNumber.push($(this).attr('data-completion-number'));
gridSize.push($(this).attr('data-grid-size'));
});
Here is the statement I have written
if ($(this).data('grid-size') == "large") {
gridColumns = 4;
gridRows = 4;
}
else {
gridColumns = 6;
gridRows = 8;
}
Here is the html
<li data-number-input="6" data-completion-number="1" data-grid-rows="8" data-grid-columns="6" data-grid-size="large"></li>
There is a syntax error in your code, you have missed a
)for thepushmethod and I’m not sure why you are using push method in an if statement, you can usedatamethod: