Tag Archives: javascript

Russian Website

I recently made this russian website for Edwards & Towers.

www.dubaipalmshoreline.ru

Simple buttons using Javascript/CSS

Sometimes there is a need to change the “class” of an object to apply a different style to it. For example you have 4 css buttons, then you want one to be “Active”, maybe highlighted different from the rest. And when you click another button, the “Active” button becomes “Inactive” and a new button becomes “Active”.

I will show you how to access it using javascript.

CSS
First you need to define your styles, “.active” and “.inactive”

.active {
background-color:#FF0000; (meaning red)
}

.inactive {
background-color:#FFFFFF; (meaning white, all buttons should start with white)
}

JAVASCRIPT

There are two options to change a class for a certain document element

#1 setAttribute(“class”, “active”);
#2 className = ‘active’;

Button = a variable passed when we click a button. For example if we click the 2nd button it passes “Button02″ as the value.

You can do this by onClick = “changeToActive(‘Button02′)”

Then in your javascript function will say

function changeToActive(x) {

document.getElementById(x).setAttribute(“class”, “active”);

}

or

function changeToActive(x) {

document.getElementById(x).setAttribute(“class”, “active”);

}

That’s it!

Remember that you need to set all buttons “Inactive” first so that they are all white. Then you choose which one to set as “Active”

I hope this works for you! Write me a comment or email me if you need help

Javascript: Slideshow

My current project requires me to have a couple of images fading-in and out. I remember that I have used this script from a website some time back. It is called the “Ultimate Slideshow Script”.

You can view more of the here

It is now updated to V2.0 i think. The one I used before was V1.5 and it I tried it on my Safari on Mac it did not work. So I tried this V2.0 and it works perfectly.

One thing to not though is the difference in the codes for both. By default the “image path, and attributes” declaration are now on the html page and not on the external javascript. The function now refers to a

file with a user specified id, rather than the whole javascript function embedded on the html. Which is great in my opinion :)

Again you can check the script here or other scripts from Dynamic Drive

10 JavaScript Quick Tips and Best Practices

Some small things that are worth looking at for javascript coders. :)

http://www.impressivewebs.com/10-javascript-quick-tips-and-best-practices/