jquery - Why am I unable to call a function in JavaScript? -


I have some javascript which is about to call two functions, but failed to do so. I suspect that I would know why, but I do not know how to fix it. Here's my jQuery:

  var is_mobile = false, page = document.location.pathname.match (/ [^ \ /] + $ /) [0]; $ (Document) .ready (function () {var ul = $ ('nav>'; ul '), li = ul.children (' li '), href = li.find (' a [href * = ' + (Page + ''] '), is404 = true; if ($ (' $ mobile '). CSS (' display ') ==' none ') {is_mobile = true;} {is_mobile} {orderList () ; ReadList);}}); / ************************************************************************************************* ***** ****** / Function Order List () {$ (li.find ('a [href * = "contact.php"]')). RemoveAttr ('style'); // step element on top. Ul.prepend (href.parent ()); If (page! = "") {Li.children ('a'). Each (function () {if (page == $ (this) .attr ('href')) {is404 = false;}}); If (is404) {// If the user is on a page which is not in the NAV, then add a 404 link at the top of the NUL. Pre-paid ("
  • 404 & lt; / a & gt; & lt; / li & gt; "); }}}; / ************************************************************************************************* ************* / * Dynamically expandable / openable * * *************************************************** ************************************************************************* ('Li : Is (ul) '). Unbind ('click'). Click (function (event) {if (this == event.target) {$ (this) .toggleClass ('expanded'); $ (this). ('Ul'). Toggle ('medium');} Return False;}) AddClass ('Collapsed'). RemoveClass ('Extended') Children ('UL'). Hide (); // To link inside the hack which cv $ ('# expList a') Unbind ('click'). Click (function () {window.open ($ (this) .attr ('href')); return false;}); // ("Expanded" ($ ('. Collapsed'). RemoveClass ('Extended'); $ ('' Extended ''); $ ('Closed'). Hide ('medium');}}};
  • I suspect that Javascript may fail to call the function because they have jQuery, but if this is the case then I I am totally unaware of the way to fix it. By the way, is_mobile is returning true when I check it on my iTouch any idea friends Thank you!

    Are you sure the function is not being called? Or is it being called But do not get the result? Try putting a breakpoint in each function, or a call to console.log (), or even an alert (), so you can see that they are being called I do not think they should be called.

    However, I think that you The scope of the variable is to define the variables ul and li inside your document .ready () function, but they orderList () And refer to readList () , which are defined at the top level. Your variables are not visible to your work and, in prepareList () , you reference instead of $ ul , ul . $ ul is not exactly defined, so when referenced for the first time it is converted to (n empty) global.

    Try defining all of these variables with the Is_mobile and then in var in document.ready () < Do not redefine with the / code> function, give them values ​​there. Or, if you do not like Global, then wrap it in a module - but you still have to show the variables for all the functions in the module or pass them in the form of a parameter.


    Comments

    Popular posts from this blog

    ios - How do I use CFArrayRef in Swift? -

    eclipse plugin - Run java code error: Workspace is closed -

    c - Error on building source code in VC 6 -