Skip to content

Tag: jquery

Slick carousel right to left

I’ve setup slick carousel to continuously scroll, however I need to to scroll in the oposite direction. Adding the RTL option didn’t seem to work. Fiddle here (currently left to right) http://jsfiddle.net/mth2ghod/ Answer Change the slidesToScroll to a -1 (it will change the slide direction)

How can I run a jQuery function only when it’s needed?

I’ve run into a problem where I have a responsive slider running on my site which has been added to an external .js file. I am running into an issue with a modal not popping up on the homepage because the page is looking for the slider which is only included on a couple of sub pages. Chrome console is

generate 4 digit random number using substring

I am trying to execute below code: I am getting error like undefined is not a function at line 2, but when I try to do alert(a), it has something. What is wrong here? Answer That’s because a is a number, not a string. What you probably want to do is something like this: Math.random() will generate a flo…

Image swapping when a variable changes

I have an html page that has one image object. I am trying to write some JavaScript but something isn’t working in the script. I have a piece of script that reads a variable and if the variable ‘e’ is equal to 1, then one image appears. If ‘e’ is anything other number then image …

Add hours in 12 hour format using javascript / jquery

How we can add hours into 12hour format time using Javascript/JQuery? Example: Add 2 hour in 12:00 AM then result should be 02:00 AM Add 8 hour in 09:00 PM then result should be 05:00 AM Answer The following function takes a string representing a time and an integer denoting the number of hours you want to ad…

Best way to scrolldown onpageload

I have the following code: The previous code attempts to scroll down after page loading. Is there any problem, as it doesn’t work for me? Answer instead of window.onload use because window.onload is fired when entire page load and document.ready is fired when DOM loads and use srcollTo instead of scroll