Created
February 13, 2014 14:32
-
-
Save slopeofhope81/8976024 to your computer and use it in GitHub Desktop.
jquery DOM manipulation #2
This file contains hidden or 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
$(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