got the following Problem width jQuery: On one site ary many div Containers with the same class called "stackgo" but with different data-attaches. Example:
<div class=\"stackgo\" data-an=\"HEY\" data-ms=\"HO\" data-me=\"HM\"></div>
I wrote some jQuery-Code to apply a Post-Massage to a PHP-File, the Mouse pointer shall change when hovering above the div-container, and send the Post-Massage when clicking on it:
$('div.stackgo').hover(function() {
document.body.style.cursor = "pointer";
$('div.stackgo').on('click', function() {
var stackgo = $(this);
var an = stackgo.data('an');
var ms = stackgo.data('ms');
var me = stackgo.data('me');
if (an != '') {
$.post('../../AJAX/schreibmaterialnei.php', {an: an, ms: ms, me: me}, function(data) {
});
}
stackgo.html('');
stackgo.html('<img src="../../img/OK_Sign.png">');
stackgo.show("pulsate",500);
alert (an + " - " + ms + " - " + me);
});
}, function() {
document.body.style.cursor = "default";
});
Sorry for the nasty written and formated Code, these are my first steps :(
Now the following Problem: At the first time on clicking on the Div-Container, everything went well. But after clicking on the second Div-Container, everything inside of the Click function will be executed two times. The more Container i click, the more "Click"-Function will be executed. (Can be seen on the mass of Alert-Windows and entrys in the Database (managed by the schreibmaterialnei.php). Not with old values, always with the new ones, just as much as i total clicked on.
Seems like it goes through every instance this class "stackgo" has made during the clicking procedure.
How can i control this? I got absolutly no idea :(
I would be very grateful for any help