Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts

    hide(); is not a function

    I am trying to use a small piece of javascript to show and hide a jcarousel lite plugin.

    After completely giving up on another piece of code I resorted back to code that works which is purely javascript.

    The only thing is, the other script would show and hide content with css which I have read does not work with jcarousel. I am suppose to use the show () and hide () function instead.

    The only problem is firebug says my my syntax is not a proper function.

    the old code is this:
    Code:
    var currentUl = 1;
    function showMe(n) {
    document.getElementById("p_"+currentUl).style.display = "none";
    document.getElementById("p_"+n).style.display = "block";
    currentUl = n;
    
    }
    the new code is:

    Code:
    var currentUl = 1;
    function showMe(n) {
    document.getElementById("p_"+currentUl).hide();
    document.getElementById("p_"+n).show();
    currentUl = n;
    
    }
    This is how I understand to plug in the show and hide function, but firebug disagrees.

    If you have any ideas as to how the hide and show should be set up please let me know.

    Thanks a lot

  • #2
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Well, the problem really comes from the fact that show() and hide() are not JavaScript functions. jQuery does have them, but if you're not including jQuery in your document, you won't really be able to use them. Not sure if other frameworks have it as well. Other than that, you can define them if you want.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

  • #3
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Hi thanks for the response,

    I made some changes to show the other elements that were hidden along with it.

    Here is what I have now:

    Code:
    var currentUl = 1;
    function showMe(n) {
    $("p_"+currentUl).hide();
    $("p_"+n).show(function ()
    	$("div#picture").show();
    	
    	$("span#picture").show();
    	$("img#space").hide();
    	);
    currentUl = n;
    
    }

    The error I am getting from firebug is: missing ' ) ' after $("div#picture").show(); argument

    obviously that isnt the problem but I am not sure what is.

    Any thoughts?

  • #4
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    ById("p_"+currentUl+"")
    ById("p_"+n+"")

    I think this will work
    I don't know how to explain it, but it works this way sometimes.

    other times this will work

    ById('p_"+currentUl+"')
    ById('p_"+n+"')

  • #5
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    I think it's because it wants a string for the ID so the whole thing has to be in quotes. Then you stick dynamic stuff in by putting it between "+ +". Sometimes, it works putting the variable between '+ +' . I have no clue which, but I try them all. LOL

  • #6
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts
    Thanks a lot for the help I have tried the suggestions and made a few more changes so now it shows and hides the elements in a proper order... The nice thing is no more errors... the problem is it still doesnt work


    Here is new code I have

    Code:
    var currentUl = 1;
    function showMe(n) {
    $("img#space").hide();
    $('"p_"+currentUl+').hide();
    $("span#picture").show();
    $("div#picture").show();
    $('"p_"+n+').show();
    	
    	
    	
    currentUl = n;
    
    };
    I have no idea what to do, so hopefully you do.

    Thanks a lot!

  • #7
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    Yeah, i don't get into Jquery stuff unless it's my own project. It's almost not worth using if you can make the effects yourself


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •