javascript - jQuery addClass() / removeClass() not working -
<ul> <li class="selected"></li> <li></li> <li></li> </ul>
that html. , selectors using right are:
$("ul li:eq(0)").removeclass('selected'); $("ul li:eq(1)").addclass('selected');
problem can not add or remove 'selected' class these elements. html , jquery both pretty straight-forward , many examples find did same way, including official jquery docs. (the script loaded before body tag, if matters)
why can't remove , add classes this?
the entire html page here
probably because forgot add $(document).ready()
,also make sure added jquery.min.js file
$(document).ready( function () { $("ul li:eq(0)").removeclass('selected'); $("ul li:eq(1)").addclass('selected'); });
Comments
Post a Comment