//Can't see anything obviously wrong with your code, but you could do
it this way instead:
$(document).ready(function(){
$("#thing").click(
function () {
$(#resultsview).toggleClass('gallery');
});
});
Then change your CSS to this:
<style>
.list {background:green;}
ul.gallery {background:red;}
</style>
Because ul.gallery is more specific than .list, simply adding that
class will override the background set with .list. Also, make sure
that you don't have a background set elsewhere for #resultsview or for
#somecontainer ul or even for div.somecontainer ul
Hope that helps.
--Karl
____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Sep 10, 2008, at 9:46 AM, unremarkable wrote:
Hi—a simple question from a newbie for you! :)
I am trying to toggle the .class of an element (I can't toggle the
#id, right?). However, what I have is not working. In short:
-----------------------------------------------------------------------
<style>
.gallery {background:red;}
.list {background:green;}
</style>
<script language="javascript" type="text/javascript">
$(document).ready(function(){
$("#thing").toggle(
function () {
$(#resultsview).removeClass('list');
$(#resultsview).addClass('gallery');
},
function () {
$(#resultsview).removeClass('gallery')
$(#resultsview).addClass('list');
});
});
</script>
<p id="thing">click</p>
<ul id="resultsview" class="list">
<li>blah</li>
<li>blah</li>
</li>
-----------------------------------------------------------------------
What am I doing wrong? Thanks for any advice!
unxx