Reputation: 3
I have three buttons, each with a jquery on.click event. In addition to the three things I want to happen with each of those events, I want a click -- whichever click the user chooses -- to render a bit of html. jQuery .one doesn't help, because I don't know which button the user will choose. And I do not want the first button click event to be disabled after it is clicked (ie you can click again). I have tried hide /unhide the html, but it shows for split second at page load which is not ideal. I am beginning programmer so do not know what else to try. Many thanks for any help.
boxOne.on('click', soundOne)
function soundOne(e) {
var mySound = soundManager.createSound({
url: ''
});
mySound.play();
results.append('<li>' + "text" '<li>');
$(this).toggleClass('clicked);
}
Let's say I have five of these boxes/click events. In addition to playing the url sound and appending some text, I would like the FIRST of these clicks (and it doesn't matter which one it is, but I don't KNOW which "box" will be clicked first) to render a heading on the page. Thanks.
Upvotes: 0
Views: 64
Reputation: 12329
Just use some css class for selector and a counter.
Lets said you add the box
class to your five elements
$(".box") // This is an array with 5 elements, the 5 boxes.
Bind the click event to that array, using the .click()
handler of jQuery, and outside of that scope declare a variable to count the clicks of the user. It should look like this
$(document).ready(function(){
var counter = 0 //the number of clicks
$(".box").click(function(){
if( counter == 0) { // the first click
//do some stuff
}
// rest of your code
counter++; // keep counting clicks!
})
})
Upvotes: 1