you could also use
$("bookmarked, .bookmarked.not") esp. if the ".not" class is used elsewhere in the html On Aug 13, 7:51 pm, "Richard D. Worth" <rdwo...@gmail.com> wrote: > You selector has an error: > $(".bookmarked,.bookmarked not") > > That will match any elements with a class of 'bookmarked' as well as any > elements of type 'not' descendant of elements with a class of bookmarked. It > seems you've copied the value from the class attribute of your element. > Problem is, the class attribute separates multiple classes by a space. But > those are totally separate classes. But inside your jQuery selector, the > space is a descendant selector > (http://www.w3.org/TR/CSS2/selector.html#descendant-selectors). So maybe you > mean: > > $(".bookmarked, .not") > > The other problem is your initial event binding will match elements that > have either of those classes at the time it is run, but since you'll be > adding and removing these classes, there may come a time where an element > has one of these classes, you'll want your event to run on it, but it won't > since it wasn't in this initial set. For that, see > > http://docs.jquery.com/Frequently_Asked_Questions#Why_do_my_events_st... > > particularly > > " > jQuery Methods > > As of jQuery 1.3, you can use the live <http://docs.jquery.com/Events/live>and > die <http://docs.jquery.com/Events/die> methods for event delegation with a > subset of event types. > " > > - Richard > > On Thu, Aug 13, 2009 at 1:31 AM, Dave Maharaj :: WidePixels.com < > > d...@widepixels.com> wrote: > > > I have 2 class options .bookmarked and .not > > > <div id="b_97fd0f" class="bookmarked not"> </div> > > > Or > > > <div id="b_97fd0f" class="bookmarked"> </div> > > > My js looks like > > > $(".bookmarked,.bookmarked not").click(function() { > > var url_id = $(this).attr('id').split('_'); > > var status = $(this).attr('class'); > > > //alert(status); > > > $.ajax({ > > type: "POST", > > url: > > '/bookmarks/bookmark/'+url_id[1], > > success: function(){ > > if (status = "bookmarked > > not") { > > //creating a bookmark > > > $('#b_'+url_id[1]).removeClass('not'); > > } else if (status = "bookmarked"){ > > //deleting the bookmark > > $('#b_'+url_id[1]).addClass('not'); > > > } > > > } > > }); > > return false; > > }); > > > If I click on a ".bookmarked not" link it removes the "not" class, but if I > > click on a "bookmarked" link it does not add the "not" class. > > > Now the bookmarks are being created and deleted in the database...just not > > changingthe div class. > > > Ideas where I went wrong? > > > Dave