Using CMS Wordpress, I have a file light.js and its directory is- wordpress ...themes/mytheme/js/light.js. This is a script of light.js:
$(document).ready(function(){$("#lightsoff").click(function(){$("body").prepend('<div id="fader" style="position: absolute;
z-index: 1000; left: 0px; top: 0px; background-color: rgba(0, 0, 0, 0.7); width: '+document.body.clientWidth+'px; height: '+document.body.clientHeight+'px; display: none;"></div>');$("#embed_holder").css("z-index","2000");$("#fader").fadeIn(500,function(){$("body")
.prepend('<div id="fader-message" style="position: absolute; z-index: 1100; top: 370px; left: 200px;
color: #fff; font-size: 18px; font-family: Calibri;">Klik dimana saja pada layar untuk mematikan mode gelap.</div>');
$("#fader").bind("click",function(){$("#fader-message")
.fadeOut(1000,function(){$("#fader-message")
.remove();$("#fader").fadeOut(500,function(){$("#fader").remove();$("#embed_holder").css("z-index","0");});});});});});});
then I created a function in function.php like this:
function lightsoff() {
wp_enqueue_script('jquery');
wp_enqueue_script('themesscript', get_template_directory_uri() . '/js/light.js', array('jquery'));
}
add_action('wp_enqueue_scripts', 'lightsoff');
In my post in wordpress, i'm trying to call function lightsoff with this script:
<a href="javascript:void(0)" onclick="lightsoff()">Mode Gelap</a></div>
I checked that light.js file has been read when the posting page is opened in source code my web:
<script type='text/javascript' src='http://....../wp-content/plugins/wp-shortcode/js/jquery.tipsy.js?ver=4.7'></script>
but when i click the Mode Gelap, no effects occur. which part is wrong? Please help me.