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.

JavaScript Conditional To Display JQuery

Featured Replies

Hello, As the title says i need to use javascript (or jquery) preferably javascript though to make an if statement for whether the jquery runs or not

 

Ive looked on google etc but nothing answers my question,

 

here is my jquery

 

<script type="text/javascript">
var aImages = new Array();
var iPrev = -1;
var iRnd = -1;

aImages[0] = "http://canvasinabox.com/preview/7/47/47-7-preview_large.jpg";
aImages[1] = "http://canvasinabox.com/preview/7/48/48-7-preview_large.jpg";
aImages[2] = "http://canvasinabox.com/preview/7/46/46-7-preview_large.jpg";
aImages[3] = "http://canvasinabox.com/preview/18/133/133-18-preview_large.jpg";
aImages[4] = "http://canvasinabox.com/preview/27/174/174-27-preview_large.jpg";
aImages[5] = "http://canvasinabox.com/preview/27/173/173-27-preview_large.jpg";
aImages[6] = "http://canvasinabox.com/preview/5/25/25-5-preview_large.jpg";

$(document).ready(function() {
	/* Define the function that triggers to fade in the background as soon as the image has loaded */
	$("img#bg").load(function() {
			/* Fade in during 3 seconds */
			$("img#bg").fadeTo(3000,1);
			/* Set the timeout to fade out the image and the description after 10 seconds*/
	   setTimeout(function() {
    	$("img#bg").fadeOut(3000);	
			/* Load the next image after 4 seconds */
		 	setTimeout(LoadImages,3000);
		 	}
		  ,9000);
		}			
	)
	/* Start the slideshow one second after the page is ready */ 
	setTimeout(LoadImages,1000);
   });

   function LoadImage(iNr) {
	/* Assign the new image to the background */
	$("img#bg").attr("src", aImages[iNr]);              	
   };

   function LoadImages() {
   	/* Select a random image number and make sure this is not equal to the previous image */
   while(iPrev == iRnd) {
   	iRnd = Math.floor(Math.random()*aImages.length);
  	}
   /* Show the selected image */
   LoadImage(iRnd);
   iPrev = iRnd;	
   };
</script>

 

and i need something like

 

<script type="text/javascript">

if() {

jquery goes here so it runs

} else {

some different jquery runs

}

</script>

 

Any ideas? Thanks in advance :)

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.