(function (){
var num = parseInt($('body').attr('data-site')) + 1,
theul = $(".submenu li:nth-child(" + num + ") a"),
newNum = num - 1,
theNewUl = $(".submenu li:nth-child(" + newNum + ") a");
console.log(theul);
theul.addClass('activex');
console.log(theNewUl);
theNewUl.addClass('lastsl');
})();
Hello, when I try to run this script console says:
“Uncaught Syntax error, unrecognized expression: li:nth-child”
Althoung I linked the jQuery source before this script,
thanks for anwsers
.data("foo")in favor of.attr("data-foo").:eq()selector. It’s zero-based, which is what you seem to want..addClass()on a separate line.10when you useparseInt(), or numbers like08will be interpreted as octal.numactually contains a number, orparseInt()will returnNaNand that will break your following code.$. It’s a useful convention to follow.Try: