Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript What’s wrong with my jQuery code?

  • This topic is empty.
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #36742
    schart
    Participant

    $(document).ready(function(){

    $('a[href="#"]').click(function(){
    event.preventDefault();
    });
    $("#infol").click(function(){
    $("#wall").slideUp();
    $("#contact").slideUp();
    $("#info").slideToggle();
    });
    $("#walll").click(function(){
    $("#info").slideUp();
    $("#contact").slideUp();
    $("#wall").slideToggle();
    });
    $("#contl").click(function(){
    $("#info").slideUp();
    $("#wall").slideUp();
    $("#contact").slideToggle();
    });

    });

    Also, jQuery is loaded, it’s just this part that doesn’t work on Firefox or IE, it works on Safari and Chrome (webkit) though. Any suggestions?

    #97084
    sliver37
    Member

    Try



    $('a[href="#"]').click(function(event){
    event.preventDefault();
    });

    #97086
    jamygolden
    Member

    @silver37 is right, that should work.

    You are calling a variable that doesn’t exist.

    #97089
    jamygolden
    Member

    Try this:

    $(document).ready(function(){

    $('a[href="#"]').click(function(e){
    e.preventDefault();
    });
    $("#infol").click(function(){
    $("#wall").slideUp();
    $("#contact").slideUp();
    $("#info").slideToggle();
    });
    $("#walll").click(function(){
    $("#info").slideUp();
    $("#contact").slideUp();
    $("#wall").slideToggle();
    });
    $("#contl").click(function(){
    $("#info").slideUp();
    $("#wall").slideUp();
    $("#contact").slideToggle();
    });

    });
    #97093
    jamygolden
    Member

    Don’t you have an html example? What do you mean by ‘its not working’. How do you know it’s not working?

    Create a little test on jsfiddle and we’ll be able to help you quickly/easily.

    P.S. If you’re using the js I added above, then the JS isn’t ‘breaking’. The syntax is fine. If you slideUp something that is already up, nothing will happen.

    #97097
    jamygolden
    Member

    Works fine for me in Chrome and Firefox 10.0.2.

    #97099
    jamygolden
    Member

    Do you have firebug?

    Open firebug, go to the console tab. Refresh the page. There should be an error, what does it say?

    #97179
    trav5567
    Member

    I know im going at this the wrong way which is why i am asking for some help, I am wanting my script to work so that when the contact div is down and you click anywhere else on the page the contact div will animate back up. If you have any suggestions for making it smoother that would be great too:)

    Thanks!

    Here is a link for what i am trying to do

    $(document).ready(function() {

    $("a.contact-btn").toggle(
    function () {
    $("#contact").animate( {"top": "0"}, 900, "linear" );
    },
    function () {
    $("#contact").animate( {"top": "-400px"}, 900, "linear" );
    });


    $('body').bind('click', function() {
    var position = $('#contact').css('marginTop');

    if ( position != '-400px') {
    $("#contact").animate( {"top": "-400px"}, 900, "linear" );
    }
    });
    });
Viewing 8 posts - 1 through 8 (of 8 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.