Answer the question
In order to leave comments, you need to log in
How to start a piece of jQuery code?
Hello. There is a piece of code
jQuery(function() {
jQuery(".fancybox").fancybox();
jQuery('.speaker').text(jQuery('.speaker').data('text'));
jQuery('.speaker').click( function () {
var speakerText = jQuery(this).closest(".row").text();
if(jQuery(this).data('lang') == 'RU') {
var speakerLang = 'Russian Female';
} else {
var speakerLang = 'Polish Female';
}
if(jQuery("#resume").hasClass("speaker_play")) {
responsiveVoice.resume();
jQuery(".speaker_play").removeAttr("id");
} else {
responsiveVoice.speak(speakerText, speakerLang, {rate: jQuery(this).data('rate')});
};
jQuery('.speaker_play').hide();
jQuery('.speaker').show();
jQuery(this).hide();
jQuery('.speaker_play').text(jQuery('.speaker_play').data('text'));
jQuery(this).closest(".speaker__inner").children('.speaker_play').show();
});
jQuery('.speaker_play').click( function () {
responsiveVoice.pause();
jQuery(this).hide();
jQuery(this).closest(".speaker__inner").children('.speaker').show();
jQuery('.speaker_play').attr('id', 'resume');
});
});
if(jQuery("#resume").hasClass("speaker_play"))
Answer the question
In order to leave comments, you need to log in
1e - Replacing the id is usually not the best practice. Much better to remake under classes.
Other than that - add an intermediate class or attribute, add/remove it after clicking.
For example, after clicking, add the class speaker_play_clicked / attribute attr-speaker-clicked="1"
As a result, the check will be:
if(jQuery("#resume").hasClass("speaker_play_clicked")) / if(jQuery("#resume") .attr("attr-speaker-clicked")==1)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question