This is a funny one, I want to display a certain div on a website only if a secret word is typed on that page (no forms are present). What is the easiest way to accomplish this with JQuery? Are there any Plugins? Thanx in advance cheers Tabaluga
jQuery :contains() Selector The :contains() selector selects elements containing the specified string. The string can be contained directly in the element as text, or in a child element. This is mostly used together with another selector to select the elements containing the text in a group (like in the example above).
We can use the replace() method with either regular expression or string as an argument. How to find the number of occurrences of a particular word or a string in a given string or paragraph. In this case, we will use the indexOf() Method in JavaScript to find the number of occurrences of desired word or substring.
To check if a div element contains specific text:Use the textContent property on the element to get the text content of the element and its descendants. Use the includes() method to check if the specific text is contained in the div . If it is, the includes() method returns true , otherwise false is returned.
Browsers 'understand' JavaScript because it is built in. JavaScript understands jQuery because it is, after all, JavaScript under the hood, not a separate, discrete language. It is JS.
if ( window.addEventListener ) {
var kkeys = [], konami = "68,73,78,78,69,82"; //this spells dinner
window.addEventListener("keydown", function(e){
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ) {
// run code here
$("#text").hide().fadeIn("slow").html('Now the website will appear.');
}
}, true);
}
you can check what letters are what by doing:
if ( window.addEventListener ) {
window.addEventListener("keydown", function(e){
$("#text").append(e.keyCode + " ");
}, true);
}
try using js-Hotkey jquery plugin:
$(document).bind('keydown', 's+e+c+r+e+t', fn);
Also you may want to inspect through KonamiCodeWebsites to see how it works:
In this website you need to enter konami code (UP + UP + DN + DN + LFT + LFT + RGT + RGT + B + A) in order to enter the website!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With