Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

JQuery help

Featured Replies

Hey everyone

 

I have the following jquery code that hides or shows a div depending on which button is pressed.

 

$(document).ready(function(){

 

$("input#1").click(function(event){

event.preventDefault();

$("div#footer3").css('display', 'none');

$("div#footer1").css('display', 'block');

});

 

$("input#2").click(function(event){

event.preventDefault();

$("div#footer3").css('display', 'block');

$("div#footer1").css('display', 'none');

 

});

 

});

 

It all works fine except I'd like to improve it a bit. When you click "input#2" more than once it cycles through the divs but I just want it to show footer3 and then if it's pressed again nothing will happen. Also when you click "input#1" after clicking "input#2" it takes you to the top of the page where as I want it to stay where the div is located. I hope this all makes sense. Here is the link to the page - http://www.dpmgroup.co.uk/preview/aspire/

 

The buttons I'm talking about are located at the bottom of the page.

 

Thanks for any help.

This should help with the first part - this could be cleaned up by using another function, but it should work (I've not tested it)

 

$(document).ready(function(){
// set default active div
var current_div = 1;

$("input#1").click(function(event){
// if div 1 is not visible change state
if(current_div != 1){
event.preventDefault();
$("div#footer3").css('display', 'none');
$("div#footer1").css('display', 'block');
current_div = 1;
}
});

$("input#2").click(function(event){
// if div 3 is not visible change state
if(current_div != 3){
event.preventDefault();
$("div#footer3").css('display', 'block');
$("div#footer1").css('display', 'none');
current_div = 3;
}
});

});

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.