1. the load()
Klaus is trying to make the point that if you do not want any data loaded
why are you running a load()?
You are running the load() into an element that you have clearly stated does
not exist, so in my opinion it is actually a bug in jQuery that is even
allowing the ajax call to be performed! Even so, you can't access what is
returned so why get anything!
Edit: Ok, I've figured out why you might be running the load - to get the
server-side program to tally score. But I still think you're lucky that it
works against a non-existent element and you might be better off using
get/post or other variants.

2. the click functions
You detail the click function attached to div.vote_against_selected, the
last steps of which are to change the class of the clicked element to be
div.vote_for_selected. Not a problem in itself.
However, say that, when you run the code that assigns the
div.vote_against_selected click function, it picks up Element A.
Element A, when clicked, will now run the function you have specified below.
As a result of running that function Element A will have its class changed.
BUT that will not affect the code that runs the next time you click Element
A! It will still run the function you have specified below because that is
the code that was assigned to its click.

The only way (outside of the behaviours plugin?) to get Element A (now with
class vote_for_selected) to run the other code you now want it to run when
clicked, is to remove (unbind) Element A's current click function (the stuff
below) and to assign (bind) a new click function with other the code.

Any clearer?

Rather than duplicate your click functions, one for each class, you could
always just add in an if statement in the code below to check the current
class of the clicked element, and perform actions accordingly?


inVINCable wrote:
> 
> 
> Hm, I don't quite exactly understand what you are saying. I simply
> load into the div.fake because I do not want any data loaded. But
> firebug DOES show an ajax action taking place everytime I click that
> element, allowing me complete the ajax request. Thank you for your
> post though, I will look into it right away.
> 
> Vince
> 
> On Jul 28, 9:36 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
>> inVINCable wrote:
>> > Hello everyone,
>>
>> > I am just about ready to throw my darn computer out the window
>> > here :P.
>>
>> > What I am doing is quite simple, I am using the .load() function to
>> > call upon a function, like so:
>>
>> > $("div.vote_against_selected").click(function(){
>> > //first load content
>> > $("div.fake").load("/stories/vote/1/" + $storyid);
>>
>> > )};
>>
>> > I should note that div.fake does NOT exist, as I do not want anything
>> > loaded, because I change the div myself, via the .html() function,
>> > like so:
>>
>> If div.fake doesn't exist, the line
>>
>> $("div.fake").load("/stories/vote/1/" + $storyid);
>>
>> doesn't do anything, so you could as well delete it. I don't understand
>> what you're trying to achieve here.
>>
>>
>>
>> > $first_new_votes_for = $votes_for * 1 + 1;
>> > $first_new_votes_against = $votes_against * 1 - 1;
>> > if ($first_new_votes_against == "") {
>> > $first_new_votes_against = "0";
>> > }
>>
>> > $("h3.votenumberfor").html($first_new_votes_against);
>> > $("h3.votenumberagainst").html($first_new_votes_for);
>>
>> > That works fine and dandy as well! Now, at the very end of my .click()
>> > function, after the load, and the .html() functions have taken place,
>> > I remove and add a class like so:
>>
>> > $(this).removeClass("vote_against_selected");
>> > $(this).addClass("vote_for_selected");
>>
>> > Again, this works perfect! I even look at look at the code with
>> > firebug, and the classes are removed, and added, which is what is
>> > exactly what is supposed to happen. But here is the kicker, I have
>> > another function that does the EXACT same thing, but is for the
>> > vote_for_selected. You will notice right above I used the addClass on
>> > the vote_for_select above, like this:
>>
>> > $(this).addClass("vote_for_selected");
>>
>> > Again, after looking at the source and verifying that the change was
>> > made, I try clicking on the new class (that was changed from
>> > vote_against_selected, to vote_for_selected when a click on
>> > vote_against_selected took place) but NOTHING happens! Ah, and I
>> > cannot understand why because looking at my source, the class is
>> > changed, so why isn't jquery recognizing this change!
>>
>> > Any tips/pointers/advice on where to go from here or any functions to
>> > look at are greatly appreciated! (Btw I have use the bind() function
>> > in every possible combination but nothing seems to work :(
>>
>> The click event wasn't bound to the element with the changed class in
>> the first place. jQuery result sets are not live. You bound the event to
>> all elements with a certain class at that time, but if another element
>> will be changed later on to belong to that class as well, that doesn't
>> automagically bind that event handler as well.
>>
>> The behaviour plugin may be of some interest, see
>> FAQ:http://docs.jquery.com/Frequently_Asked_Questions#Why_do_my_events_st...
>>
>> as well as this tutorial:http://docs.jquery.com/Tutorials:AJAX_and_Events
>>
>> --Klaus
> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Allowing-a-.click%28%29-function-to-occur-as-many-times-as-needed-in-tandem-with-.load%28%29---tf4162680s15494.html#a11851763
Sent from the JQuery mailing list archive at Nabble.com.

Reply via email to