Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Adds the given class to 1 element from the selection and return it:
// extend jQuery:
$.fn.setClassRand = function(cssClass) {
return this.eq( Math.floor( Math.random() * this.length ) ).addClass(cssClass);
//add the class "teaser__video--active" and play it:
var video = $(".teaser__video").setClassRand("teaser__video--active");
if (video.length) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.