Skip to content

Instantly share code, notes, and snippets.

@slopeofhope81
Created February 13, 2014 14:32
Show Gist options
  • Save slopeofhope81/8976024 to your computer and use it in GitHub Desktop.
Save slopeofhope81/8976024 to your computer and use it in GitHub Desktop.
jquery DOM manipulation #2
$(document).ready(function () {
$(".section").click(checkForCode);
function getRandom(n) {
return Math.floor(Math.random() * n);
}
var hideCode = function () {
var num = getRandom(4);
$(".section").each(function (index, value) {
if (num == index) {
$(this).append("<span id='
has_discount'></span>");
return false;
};
});
};
hideCode();
function checkForCode() {
var msg;
if ($.contains(this, document.getElementById("has_discount"))) {
var numRan = getRandom(10);
msg = "<p>Your discount is" + numRan + "</p>";
} else {
msg = "<p>sorry no discount</p>";
}
$(this).append(msg);
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment