Created
October 20, 2020 09:50
-
-
Save Megafry/62e557b13c234c003299cf3699aa1262 to your computer and use it in GitHub Desktop.
Adds the given class to 1 element from the selection and return it:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// extend jQuery: | |
$.fn.setClassRand = function(cssClass) { | |
return this.eq( Math.floor( Math.random() * this.length ) ).addClass(cssClass); | |
}; | |
//usage: | |
//add the class "teaser__video--active" and play it: | |
var video = $(".teaser__video").setClassRand("teaser__video--active"); | |
if (video.length) { | |
video[0].play(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment