I have a bit of JQuery that creates a mobile menu for a responsive design. I ran the code through a code sniffer and it’s telling me that “Inline control structures are not allowed“.
The area of code in question is:
else {
$('#main-menu li').each(function () {
if ($(this).children('ul').length)
$(this).append('<span class="drop-down-toggle"><span class="drop-down-arrow"></span></span>');
});
… and the specific line from the above is:
if ($(this).children('ul').length)
I tried to Google search “Jquery inline control structures” but did not come up with much.
Here is a pastebin of the entire function for reference. I am guessing the code can be rephrased but I have no reference on which to change it. The code actually works so I am not sure if it’s necessarily a syntax error per se.
It probably wants you to use braces:
It is always safer to use braces with
ifandelse. It never causes a problem and can occasionally prevent an accidental error (often when later editing the code).