Edit: Ok just to get this straight, you use the not selector to filter attributes in a particular tag and not to filter child elements?
Can someone help me out whether I have some sort of syntax error here, or may be I’m not understanding the concept?
I have list items which when you click on, they change the font size of the body. Now the list item is within the body so its font changes to. I would like this UL to remain with the same font. so I am using the .not(“#ulSize”) as can be seen below. But this is not working.
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#liSmall").click(function () {
$('body').not('#ulSize').removeClass('large normal').addClass('small');
});
$("#liNormal").click(function () {
$('body').not('#ulSize').removeClass('large small').addClass('normal');
});
$("#liLarge").click(function () {
$('body').not('#ulSize').removeClass('small normal').addClass('large');
});
});
</script>
<style type="text/css">
.large
{
font-size: large;
}
.normal
{
font-size: medium;
}
.small
{
font-size: small;
}
</style>
</head>
<body>
<ul id="ulSize">
<li id="liSmall">Small Font</li>
<li id="liNormal">Normal Font</li>
<li id="liLarge">Large Font</li>
</ul>
Text in here!!!
</body>
</html>
Thank you guys
I’d recommend refactoring your JS to something like this:
And then hard-code a font-size on the
#ulSizelist, and let the browser do the rest.