Reputation: 213
In my spelling game, when a letter is complete I want the next word to spell to be selected automatically. At the moment the user has to click the button to go to the next.
At the moment I have this
var noExist = $('td[data-word=' + listOfWords[rndWord].name + ']').hasClass('wordglow2');
if (noExist) {
$('.minibutton').click('enable');
} else {
$('.minibutton').click('disable');
$("#mysoundclip").attr('src', listOfWords[rndWord].audio);
audio.play();
$("#mypic").attr('src', listOfWords[rndWord].pic);
pic.show();
}
});
I have tried replacing the line...
$('.minibutton').click('enable');
to...
$('.minibutton').trigger('click')
and it won't work, any ideas?
THANKS
Upvotes: 0
Views: 867
Reputation: 19022
You should consider refactoring so that the action of going to the next word is independent of how it is triggered. That would be cleaner and you don't have to do tricks like faking clicks.
function gotoNextWord(){
// ...
}
and setup
$('.minibutton').on('click', gotoNextWord);
and I'm not entirely grokking your code, but it would become something like this:
// ...
if (noExist) {
gotoNextWord();
} else {
// ...
}
Upvotes: 2
Reputation: 4539
Try this
if (noExist) {
$('.minibutton').click('enable'); // if your button successfully enable then write below line after it.
$('.minibutton').click();
}
Upvotes: 0
Reputation: 1524
to Disable
$('.minibutton').unbind('click').click(function(e){
e.preventDefault();
});
to enable
$('.minibutton').unbind('click');
Upvotes: 0