I'm pretty new to jQuery and I have a bit of an issue with some jQuery logic I'm making so I've included the code below. I have the first if statement checking the screen resolution, the 2nd if statement is checking how many list items there are and to only run if 1 or more and the final if statement making sure that only 1 instance of the append is running as it's inside an AJAX request so had issues with multiple instance being output.
Any suggestions as to where I've gone wrong? Any help would be awesome, thank you :)
HTML:
<ul class="swatches color clearfix">
<li class="selectable">
<span class="swatchanchor js-swatchanchor js-colorswatch">
List Item 1
</span>
</li>
<li class="selectable">
<span class="swatchanchor js-swatchanchor js-colorswatch">
List Item 2
</span>
</li>
</ul>
jQuery
if($(window).width() >= 1358){
var $lis = $('ul.swatches.color li');
var $jsColorMsgCheck = $('.jsColorMsgError');
if ($lis.length > 1) {
if ($jsColorMsgCheck.length) {
$(".swatches.color").parent().append($('<div class="jsColorMsgError">PLEASE SELECT A COLOUR</div>'));
}
}
}
Aucun commentaire:
Enregistrer un commentaire