Skip to main content

Posts

jquery $(selector).ready() code running even if no element was matched

I am using this code to only run this js on certain pages. $("body#action_new").ready(function() { console.log($("body#action_new")); console.log($("body#action_new").length); console.log("code is running"); } Even though body#action_new does not exist, the code is running. the two console.logs print out: [] 0 code is running What gives?

Functions in Jquery [closed]

I have got many dropdowns in my site and i want to make a reusable function with jquery so i can save a lot of code just by a single function. Can any one help me out in this regard... For an example <div id="clickMe"> <div id="showMe"> <div>I am dropdown item</div> </div> </div> right now i am using it like this way... $(document).ready(function() { $("#clickMe").click(function(e) { e.preventDefault(); $("#showMe").toggle(); $("#clickMe").toggleClass("menu-open"); }); $("#showMe").mouseup(function() { return false }); $(document).mouseup(function(e) { if($(e.target).parent("#clickMe").length==0) { $("#clickMe").removeClass("menu-open"); $("#showMe").hide(); } }); }); but now i want to make it more reusable... Thanks in advance..

How to find out whether an element is in a hidden iframe

Using jQuery, one can easily find out whether a particular element is visible using $(element).is(':visible') While having some limitations (doesn't cover css visibility hidden or the actual visibility in the viewport, i.e. whether it's covered by other elements or scrolled away), I find it being useful for my scenario. The catch is, it only works within one iframe. If the element has any parent within its document with display:none; , it returns false. If the whole document is included in an iframe which has display:none , it returns true. Is it possible to somehow detect this in another way ?

how to use global variable with phonegap navigator.notification.confirm?

i have this situation: <a href="#" onClick="submitNotification(1);">click1</a> <a href="#" onClick="submitNotification(2);">click2</a> <a href="#" onClick="submitNotification(3);">click3</a> function submitNotification(cdata){ navigator.notification.confirm( 'do you like '+cdata+' option ', submit, 'notice', 'Yes,No' ); function submit(button){ if (button == 1){ alert(id); //or alert(cdata); } else if (button == 2){ ... } } so, i click on a link, 1 or 2 ... gets send to submitNotification where i get a message: do you like 1 option or do you like 2 option or ... depending on what link i click. this function calls submitVote and sends button var to it somehow. yes means 1 and no means 2 . the problem is that i cant get id or cdata from the original link.

How to find out whether an element is in a hidden iframe

Using jQuery, one can easily find out whether a particular element is visible using $(element).is(':visible') While having some limitations (doesn't cover css visibility hidden or the actual visibility in the viewport, i.e. whether it's covered by other elements or scrolled away), I find it being useful for my scenario. The catch is, it only works within one iframe. If the element has any parent within its document with display:none; , it returns false. If the whole document is included in an iframe which has display:none , it returns true. Is it possible to somehow detect this in another way ?

jquery $(selector).ready() code running even if no element was matched

I am using this code to only run this js on certain pages. $("body#action_new").ready(function() { console.log($("body#action_new")); console.log($("body#action_new").length); console.log("code is running"); } Even though body#action_new does not exist, the code is running. the two console.logs print out: [] 0 code is running What gives?