Not able to execute Jquery hide and show
-
I am trying to hide and show p tag on two different button click but I am not able to get it .
Error I am getting :
"Uncaught TypeError: Cannot call method 'addEventListener' of null", source:file:///android_asset/www/js/index.js (48)
p1.html
<p id="hidep">If you click on the "Hide" button, I will disappear.</p> <button id="hide" onclick="hideButton()">Hide</button> <button id="show" onclick="hideButton()">Show</button>
index.js
function onLoad() { document.addEventListener("deviceready", onDeviceReady, false); } function onDeviceReady() { document.getElementById('demo').addEventListener("click", printMsg, false); document.getElementById('show').addEventListener("click", hideButton, false); document.getElementById('hide').addEventListener("click", hideButton, false); document.addEventListener("pause", onPause, false); document.addEventListener("resume", onResume, false); document.addEventListener("menubutton", onMenuKeyDown, false); } function hideButton(){ $("#hide").click(function(){ $("#hidep").hide(); }); $("#show").click(function(){ $("#hidep").show(); }); }
-
@Ashish Well, the error says
Cannot call method 'addEventListener' of null
. That means that either you misspelled the variable/object name or there is a timing issue and it is not ready yet. You need to find which line of code callingaddEventListener
throws the error.
-
Ya I got the result actually the listener for id demo was not doing anything and when i removed that it started working Thanks again