Forums Get help. Give help.
[Solved] What's wrong with my jQuery code?
-
$(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? -
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();
});
}); -
Not working, but I know the problem is in the slideUp/slideToggle thingy. Maybe because the ones that slide up are sometimes already up, causing the whole code to break or something? I know this because I have a similar code on the settings page, without the preventDefault and it's not working properbly there either. When I click on either "infol", "walll" or "contl", it just doesn't do anything.
-
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. -
http://schart.net/profile.php?id=1
Try opening that in Mozilla, and clicking on the tabs. In chrome, the current one will slide up and the one you clicked on will slide down, while on Mozilla it won't work. I stated all of that above. -
-
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" );
}
});
});
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Categories
- All Discussions15,493
- CSS Combat7,193
- Other Discussions3,820
- JavaScript Jungle2,455
- PHP Problems2,025
Tips
Just some helpful hints to get the most out of the forums.
